Reputation: 56694
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
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