Coding help to exclude in Directory.GetFiles Files which are starting with PL_ or AUS_


Is there a way to exclude in Direcotry.GetFiles specific documents when they beginn with PL_ e.g. odr AUS_

I am having this code but it doesnt work very well I need the exlude the files to check when they start with PL_ or AUS_:

Any ideas?


Try below expression.

         Directory.GetFiles("C:\Users\msauro\Desktop\Tester\ToName","*.pdf",SearchOption.AllDirectories).Where(Function(x) Not x.StartsWith("PL") OR Not x.StartsWith("AUS")).ToArray
1 Like

@david.mitrovic – Please try like below…

 Directory.GetFiles("YourFolderPath",". pdf", SearchOption.AllDirectories).Where(Function(n) not path.GetFileName(n).Startswith("PL_") and path.GetFileName(n).Startswith("AUS_") and).ToArray

thanks a lot

1 Like

thanks for your alternative

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.