C# Searching for files and folders except in certain folders

No there isn’t as far as I know. But you could use very simple LINQ to do that in a single line.

var s1 = Directory.GetFiles(path , "*.*", SearchOption.AllDirectories).Where(d => !d.StartsWith("<EXCLUDE_DIR_PATH>")).ToArray();

You can easily combine multiple exclude DIRs too.

Leave a Comment