How to delete all files from a specific folder? [closed]
I save files in a specific folder at run time. After some time, I want to delete them programmatically. How do I delete all files from a specific folder?
string[] filePaths = Directory.GetFiles(@"c:\MyDir\");
foreach (string filePath in filePaths)
File.Delete(filePath);
Or in a single line:
Array.ForEach(Directory.GetFiles(@"c:\MyDir\"), File.Delete);
You can do it via FileInfo or DirectoryInfo:
DirectoryInfo di = new DirectoryInfo("TempDir");
di.Delete(true);
And then recreate the directory