Skip to content
Advertisement

Java PathMatcher not working properly on Windows

I try to implement a JUnit test for my SimpleFileVisitor but the used PathMatcher doesn’t work properly on Windows. The problem seems to be the PathMatcher with a regex pattern behaves different on Linux and Windows:

JavaScript

But I’ve a longer list in my regex for multiple files which are not easy to migrate to glob syntax. Otherwise I’ve nested groups which is not allowed or an even longer list if I wrote every pattern as a not-grouped pattern.

What is the best way to do this in a cross-platform manner?

Advertisement

Answer

If you want a version which does not include Windows file separator character in the regex when the code is run on Linux, you can also use:

JavaScript

This prints same output on Linux/Windows.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement