Is there any way to exclude certain directories from SearchOption using LINQ command like this
string path = "C:SomeFolder";
var s1 = Directory.GetFiles(path , "*.*", SearchOption.AllDirectories);
var s2 = Directory.GetDirectories(path , "*.*", SearchOption.AllDirectories);
The path consists of Sub1 and Sub2 Folders with certain files in it. I need to exclude them from directory search.
Thanks
This Worked:
string[] exceptions = new string[] { "c:\SomeFolder\sub1",
"c:\SomeFolder\sub2" };
var s1 = Directory.GetFiles("c:\x86", "*.*",
SearchOption.AllDirectories).Where(d => exceptions.All(e =>
!d.StartsWith(e)));
This helped with Exceptions
See Question&Answers more detail:os