Hi, I want to delete a set of files but in an efficient way.
I have an array of string called filesToUse that contains the list of files names to keep in disk. Then, I search in my folder all files but I need check every files do not match with any element in my array. By example:
Code:
foreach(string sFile in System.IO.Directory.GetFiles("C:\\*.bmp"))
{
bool flag = false;
foreach (string s in filesToUse)
if (s.Equals(sFile))
flag = true;
if(flag) System.IO.File.Delete(sFile); //anyone of these are in filesToUse
}
I think that both foreach is unnecessary, any better solution without use 2 for's?
Thanks in advance
esmitt
03-25-2011, 12:00 PM
tkorsano
forfiles.exe
hi there,
this is not a dotnet solution, but deleting files is recommended with forfiles.exe utility.