The following code snippet checks if a directory has subdirectories and files and delete them before deleting a directory.
Nội dung
Check if a directory Exists
The Directory.Exists method checks if the specified directory exists. The following code snippet checks if a directory exists or not and deletes only if the directory exists.
string root = @"C:Temp";
// If directory does not exist, don't even try
if (Directory.Exists(root))
{
Directory.Delete(root);
}