Search code examples
javapathmatchnioglob

Why does PathMatcher doesn't match path?


I research glob patterns.

I wrote simple example:

PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:D:\\folder1\\folder2\\**");
boolean isMatches  = matcher.matches(Paths.get("D:\\folder1\\folder2\\folder3"));
System.out.println(isMatches);

This code returns false.

If I use one star in pattern - I see same result.

What do I wrong?


Solution

  • Try with \\\\ in path expression, to escape directory and reg expression

    PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:D:\\\\dev\\\\server\\\\**");
    boolean isMatches  = matcher.matches(Paths.get("D:\\dev\\server\\web"));
    System.out.println(isMatches);