确定任何级别的子文件夹之一上是否有文件夹 c#

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

在 C# 上是否有任何有效的方法来确定文件夹的任何级别中是否存在名称为 'sub' 的子文件夹。

意思是,给定路径我想确定路径的子树上是否有任何级别包含文件夹'sub'。

谢谢!

您可以使用Directory.GetDirectories()Directory.EnumerateDirectories()方法,指定在搜索操作中包括当前目录及其所有子目录:

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