Code: Select all
public class FileVisitorTest extends SimpleFileVisitor<Path> {
private final PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:*.c");
private static int count;
public int getCount() {
return count;
}
public FileVisitResult visitFile(Path path, BasicFileAttributes attributes) {
Path name = path.getFileName();
System.out.println(name);
if (name != null && matcher.matches(name)) {
count++;
}
return FileVisitResult.CONTINUE;
}
public static void main(String[] args) throws IOException {
FileVisitorTest fileVisitorTest = new FileVisitorTest();
Files.walkFileTree(Paths.get("C:\\Users\\<user>\\workspace\\ocp\\resources"), fileVisitorTest);
System.out.println(fileVisitorTest.getCount());
}
}