public static void EmtpyFolder(this System.IO.DirectoryInfo directory)
{
foreach(System.IO.FileInfo file in directory.GetFiles()) { file.Delete(); }
foreach(System.IO.DirectoryInfo subDirectory in directory.GetDirectories())
{
subDirectory.Delete(true);
}
}
System.IO.DirectoryInfo directory = new System.IO.DirectoryInfo(@"C:\Temp");
directory.EmtpyFolder();
WARNING - Double check the directory you are passing before running the snippet.
Hope it helps :)
How to delete all subfolders and files in a directory?
Below is just a snippet to delete files and sub-directories in a folder... They are a lot of ways to do this using C# .. below is one of them !!