DirectoryHelper { public static void applyToFiles(final Path from, final Function<Path, FileVisitResult> func) throws IOException { validateDirectory(from); Files.walkFileTree(from, DEFAULT_FILE_VISIT_OPTIONS, Integer.MAX_VALUE, new FunctionFileVisitor(func)); } private  DirectoryHelper(); static void mkdir(final Path dir); static void mkdir(final File dir); static File mkdir(final File parent, final String child); static void clean(final Path dir); static boolean cleanIfExists(final Path dir); static void empty(final Path dir); static boolean emptyIfExists(final Path dir); static void delete(final Path dir); static void delete(final Path dir, @Nullable final Predicate<Path> excludeFilter); static boolean deleteIfExists(final Path dir); static boolean deleteIfExists(final Path dir, @Nullable final Predicate<Path> excludeFilter); static void copy(final Path from, final Path to); static void copy(final Path from, final Path to, @Nullable final Predicate<Path> excludeFilter); static boolean copyIfExists(final Path from, final Path to); static boolean copyIfExists(final Path from, final Path to, @Nullable final Predicate<Path> excludeFilter); static void move(final Path from, final Path to); static boolean moveIfExists(final Path from, final Path to); static void copyDeleteMove(final Path from, final Path to, @Nullable final Predicate<Path> excludeFilter); static boolean copyDeleteMoveIfExists(final Path from,
                                               final Path to,
                                               @Nullable final Predicate<Path> excludeFilter); static void apply(final Path from, final Function<Path, FileVisitResult> func); static void applyToFiles(final Path from, final Function<Path, FileVisitResult> func); static final Set<FileVisitOption> DEFAULT_FILE_VISIT_OPTIONS; }
@Test public void applyToFiles() throws IOException { final ArrayList<String> fileNames = Lists.newArrayList(); final ArrayList<String> dirNames = Lists.newArrayList(); final Function<Path, FileVisitResult> tf = new Function<Path, FileVisitResult>() { @Override public FileVisitResult apply(final Path input) { if (Files.isDirectory(input)) { dirNames.add(input.getFileName().toString()); } else if (Files.isRegularFile(input)) { fileNames.add(input.getFileName().toString()); } return FileVisitResult.CONTINUE; } }; DirectoryHelper.applyToFiles(root.toPath(), tf); assertThat(fileNames, hasSize(9)); assertThat(dirNames, hasSize(0)); }