I have a root folder inside which there are multiple folders with multiple files in it.
All sub folders will have multiple files but only 1 file which will have ‘Consolidated’ term in filename.
So, I wanted to delete all the files except the ones having consolidated in it.
I used Directory.GetFiles(Path,"*", searchoption.AllDirectories)
Then to check term i used the contains method inside for loop
**If (NOT file.ToString.ToLower.Contains(“consolidated”) , then delete.
Straight enough, it works perfectly, it deletes all files except consolidated ones, but shockingly sometimes it deletes all the files even the ones’ containing consolidated.
My file names remain same so it’s not that file names are changing so it deleted all, I tried several ways to replicate and figure out the issue but couldn’t find, it’s adhoc, sometimes, it works perfectly whereas at times it deletes all the files, ultimately I had to change the pattern in directory.get files method to match the files which are supposed to be deleted, this works fine.
Has any one ever faced this issue while using contains with 'Delete; file activity