JL. JL. - 9 days ago 5
C# Question

How to delete all files and folders in a directory?

Using C#, how can I delete all files and folders from a directory, but still keep the root directory?

Answer
System.IO.DirectoryInfo di = new DirectoryInfo("YourPath");

foreach (FileInfo file in di.GetFiles())
{
    file.Delete(); 
}
foreach (DirectoryInfo dir in di.GetDirectories())
{
    dir.Delete(true); 
}