Java PathMatcher and SimpleFileVisitor without startingDir

94 Views Asked by At

In this example http://docs.oracle.com/javase/tutorial/essential/io/find.html

We have a SimpleFileVisitor implementation that uses PathMatcher to accept (or not) a visited file.

Path startingDir = Paths.get(args[0]);
String pattern = args[2];

Finder finder = new Finder(pattern);
Files.walkFileTree(startingDir, finder);

I want the user to be able to specify any file anywhere using a glob pattern, so I don't have a startingDir better than "/".

Example:

/home/bianca/myapp-*/config/*.properties

Is there an elegant way to fetch those properties files without visiting every single file in the whole /home/bianca home folder?

Other example:

/aaa/*/ccc/ddd/**/*.properties

Here a smarter implementation could spare us from visiting a path like /aaa/bbb/hhh since none of the files in it will even match.

0

There are 0 best solutions below