How to delete a directory recursively
When you want to delete a directory recursively, you can use the overload of the Delete method of the Directory class.
Setting the second argument to true, you can delete the entire contents of the selected directory recursively.
using System.IO;
class DeleteDirectoryTest
{
public static void Main()
{
// Path of the directory to be deleted.
string pathOfDirectory = "C:\\Documents and Settings\\User\\MyDirectory";
// Delete the directory and all contents
Directory.Delete(pathOfDirectory);
}
}
Category: C#