Delete the directory any subdirectories and files in the directory in CSharp
Description
The following code shows how to delete the directory any subdirectories and files in the directory.
Example
using System;// www. ja v a2s . c o m
using System.IO;
class Test
{
public static void Main()
{
// Specify the directories you want to manipulate.
string path = @"c:\MyDir";
string subPath = @"c:\MyDir\temp";
try
{
Console.WriteLine("I am about to attempt to delete {0}", path);
Directory.Delete(path, true);
Console.WriteLine("The Delete operation was successful.");
}
catch (Exception e)
{
Console.WriteLine("The process failed: {0}", e.ToString());
}
finally {}
}
}
The code above generates the following result.