如何使用 FileSystemGlobbing.Matcher

can*_*cat 8 .net c#

如何使用该类Microsoft.Extensions.FileSystemGlobbing.Matcher。我阅读了文档,但我仍然不明白。

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

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

预期的:

foo/b.md
bar/a.txt
Run Code Online (Sandbox Code Playgroud)

实际的:

// nothing
Run Code Online (Sandbox Code Playgroud)

TN.*_*TN. 4

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

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" });
Run Code Online (Sandbox Code Playgroud)