ROMANIA_engineer
ROMANIA_engineer

Reputation: 56694

Why doesn't glob:* match any path in PathMatcher?

Let's have:

Path path = Paths.get("C:\\1.txt");

The following code prints "true":

PathMatcher matcher = FileSystems.getDefault().getPathMatcher("regex:.*");
System.out.println(matcher.matches(path));

but the following code prints "false":

PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:*");
System.out.println(matcher.matches(path));

Why?

I was expecting to have true in both approaches.

According to Glob page from Wikipedia, the wildcard * means:

matches any number of any characters including none

Details:

Upvotes: 1

Views: 961

Answers (1)

Anas EL KORCHI
Anas EL KORCHI

Reputation: 2048

As @T.J Crowder said you should good to go with this :

PathMatcher matcher2 = FileSystems.getDefault().getPathMatcher("glob:**");
System.out.println(matcher2.matches(path));

For more info see this which says :

The ** characters matches zero or more characters crossing directory boundaries.

Upvotes: 1

Related Questions