Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use FileSystemGlobbing.Matcher

Tags:

c#

.net

How to use the Microsoft.Extensions.FileSystemGlobbing.Matcher class. I read the documentation, but I still don't understand it.

I expect to be able to exclude the specified folder(use glob), but the code does not work:

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

Expected:

foo/b.md
bar/a.txt

Actual:

// nothing
like image 986
candycat Avatar asked Oct 15 '22 09:10

candycat


1 Answers

You have to specify what to include:

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" });
like image 83
TN. Avatar answered Nov 01 '22 16:11

TN.