Which method of deleting files has the best performance?
- Deleting per file, or
- Deleting whole directory with files at once and recreating the directory
Just to note the root directory must be still there, so either I can do:
var photo_files = Directory.EnumerateFiles(item_path, "*.jpg", SearchOption.TopDirectoryOnly);
foreach (var photo in photo_files)
{
File.Delete(photo);
}
Or delete the whole directory and then create it again.
How much performance difference would there be for 10000 or even 100000 files?
P.S. Just to clarify, .NET has no function to delete all files in a folder at once and leaving the directory.
Directory.Delete
moves recursively through files withWin32Native.FindNextFile
. – Bellyband