Here you can find the source of listFiles(Path path, String glob)
public static List<Path> listFiles(Path path, String glob) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.PathMatcher; import java.util.ArrayList; import java.util.List; public class Main { public static List<Path> listFiles(Path path, String glob) throws IOException { final PathMatcher matcher = path.getFileSystem().getPathMatcher("glob:" + glob); final DirectoryStream.Filter<Path> filter = new DirectoryStream.Filter<Path>() { @Override/*from w w w .j a v a2 s.c o m*/ public boolean accept(Path entry) throws IOException { return Files.isDirectory(entry) || matcher.matches(entry.getFileName()); } }; List<Path> result = new ArrayList<Path>(); try (DirectoryStream<Path> stream = Files.newDirectoryStream(path, filter)) { for (Path entry : stream) { if (Files.isDirectory(entry)) { result.addAll(listFiles(entry, glob)); return result; } result.add(entry); } } return result; } public static List<Path> listFiles(Path path, String glob, String exclusionGlob) throws IOException { final PathMatcher matcher = path.getFileSystem().getPathMatcher("glob:" + glob); final PathMatcher excludeMatcher = path.getFileSystem().getPathMatcher("glob:" + exclusionGlob); final DirectoryStream.Filter<Path> filter = new DirectoryStream.Filter<Path>() { @Override public boolean accept(Path entry) throws IOException { return Files.isDirectory(entry) || (matcher.matches(entry.getFileName()) && !excludeMatcher.matches(entry.getFileName())); } }; List<Path> result = new ArrayList<Path>(); try (DirectoryStream<Path> stream = Files.newDirectoryStream(path, filter)) { for (Path entry : stream) { if (Files.isDirectory(entry)) { result.addAll(listFiles(entry, glob, exclusionGlob)); return result; } result.add(entry); } } return result; } }