Skip to content

Instantly share code, notes, and snippets.

@electrum
Created July 23, 2012 23:46
Show Gist options
  • Save electrum/3166968 to your computer and use it in GitHub Desktop.
Save electrum/3166968 to your computer and use it in GitHub Desktop.
Java Find Matching Files
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