[C#] How to delete a directory in C#

Byadmin

Mar 12, 2019 , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
Chia sẻ

The Directory.Delete method deletes an empty directory from the specified path permanently. If a directory has subdirectories and/or files, you must delete them before you can delete a directory. If you try to delete a file that is not empty, you will get an error message. The following code snippet deletes the destination file.

string root = @"C:\Temp";
// If directory does not exist, don't even try
if (Directory.Exists(root))
{
    Directory.Delete(root);
}

 


Chia sẻ
Xem thêm  [C#] How to Copy a directory in C#

By admin

Leave a Reply

Your email address will not be published. Required fields are marked *