Created
July 23, 2012 23:46
-
-
Save electrum/3166968 to your computer and use it in GitHub Desktop.
Java Find Matching Files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static List<Path> listMatchingFiles(Path start, String glob) | |
throws IOException | |
{ | |
final ImmutableList.Builder<Path> list = ImmutableList.builder(); | |
final PathMatcher matcher = start.getFileSystem().getPathMatcher("glob:" + glob); | |
Files.walkFileTree(start, new SimpleFileVisitor<Path>() | |
{ | |
@Override | |
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) | |
throws IOException | |
{ | |
if (matcher.matches(file)) { | |
list.add(file); | |
} | |
return FileVisitResult.CONTINUE; | |
} | |
}); | |
return list.build(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment