如何使用FileSystemGlobbing.Matcher

如何使用microsoft.Extensions.FileSystemGlobbing.Matcher类。我读了documentation,但还是不明白。

我希望能够排除指定的文件夹(使用glob),但是代码不起作用:

var matcher = new Matcher();
matcher.AddExclude("foo/*.txt");
matcher.Match(new[] { "foo/a.txt","foo/b.md","bar/a.txt" }); // HasMatches: false

预期:

foo/b.md
bar/a.txt

实际:

// nothing
aazhenzhen 回答:如何使用FileSystemGlobbing.Matcher

您必须指定要包括的内容:

var matcher = new Matcher();
matcher.AddInclude("**"); // <-- this line is added
matcher.AddExclude("foo/*.txt");
matcher.Match(new[] { "foo/a.txt","foo/b.md","bar/a.txt" });
,

关于这门课的信息不多。

所以,以防万一有人需要和我一样的东西,下面是我在我的所有子目录中找到所有 config.json 文件的方法,不包括 node_modules 文件夹(否则会花费太长时间):

var configPaths = new Matcher()
  .AddInclude("**/config.json")
  .AddExclude("**/node_modules/")
  .Execute(new DirectoryInfoWrapper(new DirectoryInfo(rootDir)))
  .Files
  .Select(x => x.Path)
  .ToArray();
本文链接:https://www.f2er.com/3162343.html

大家都在问