Programmer
Programmer

Reputation: 381

Determine if there is folder on one of the subfolder in any level c#

Is there any efficient way on C# to determine whether exists subfolder with name 'sub' in any level of the folder.

Means, given path I would like to determine if there is any level on the subtree of path which contais folder 'sub'.

Thanks!

Upvotes: 1

Views: 49

Answers (1)

Arturo Menchaca
Arturo Menchaca

Reputation: 15982

You can use Directory.GetDirectories() or Directory.EnumerateDirectories() methods, specifying that includes the current directory and all its subdirectories in a search operation:

var subDirs =  Directory.GetDirectories("ROOT PATH", "sub", SearchOption.AllDirectories);

Upvotes: 3

Related Questions