JL. JL. - 1 year ago 110
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 Source
System.IO.DirectoryInfo di = new DirectoryInfo("YourPath");

foreach (FileInfo file in di.GetFiles())
foreach (DirectoryInfo dir in di.GetDirectories())
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download