When you delete a directory, this is one entry in the table of the main drive files, whereas if you delete each file, then there is a write operation for each file. Thus, it is more efficient to delete the directory and recreate it.
After sharing with frustrated @Mr, I would suggest the following amendment to my answer:
If you need to do this βa lotβ, you can create an extension method for yourself that looks like this:
public static class IOExtension { public static void PurgeDirectory(this DirectoryInfo d) { string path = d.FullName; Directory.Delete(d.FullName,true);
so that you can just call this in the DirectoryInfo class, for example ...
Directory Info di = new DirectoryInfo(path); di.PurgeDirectory();
source share