我想遍历一个目录并停在第一个不以“@”结尾的文件夹
这是我到目前为止所尝试的(基于此站点的另一个问题):
string rootPath = "D:\\Pending\\Engineering\\Parts\\3";
string targetPattern = "*@";
string fullPath = Directory
.EnumerateFiles(rootPath, targetPattern, SearchOption.AllDirectories)
.FirstOrDefault();
if (fullPath != null)
Console.WriteLine("Found " + fullPath);
else
Console.WriteLine("Not found");
我知道这*@
是不正确的,不知道该怎么做。
我也遇到了SearchOption
Visual Studio 的问题,说“这是一个模棱两可的参考”。
最终,我希望代码获取此文件夹的名称并使用它来重命名不同的文件夹。
最终解决方案
我最终使用了 dasblikenlight 和 user3601887 的组合
string fullPath = Directory
.GetDirectories(rootPath, "*", System.IO.SearchOption.TopDirectoryOnly)
.FirstOrDefault(fn => !fn.EndsWith("@"));