1

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.

benji
  • 2,331
  • 6
  • 33
  • 62
  • Hint: The [preVisitDirectory](http://docs.oracle.com/javase/8/docs/api/java/nio/file/FileVisitor.html#preVisitDirectory-T-java.nio.file.attribute.BasicFileAttributes-) method of FileVisitor does not have to return FileVisitResult.CONTINUE. – VGR May 20 '16 at 18:19
  • Right but you can't match its path against the glob pattern. – benji May 20 '16 at 18:29

0 Answers0