@Test public void empty() throws IOException { DirectoryHelper.empty(root.toPath()); assertThat(root, exists()); assertThat(root, isDirectory()); assertThat(root, isEmptyDirectory()); }
public static void empty(final Path dir) throws IOException { validateDirectory(dir); Files.walkFileTree(dir, DEFAULT_FILE_VISIT_OPTIONS, Integer.MAX_VALUE, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(final Path f, final BasicFileAttributes attrs) throws IOException { Files.delete(f); return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(final Path d, final IOException exc) throws IOException { if (exc != null) { throw exc; } else if (dir != d) { Files.delete(d); } return FileVisitResult.CONTINUE; } } ); }
DirectoryHelper { public static void empty(final Path dir) throws IOException { validateDirectory(dir); Files.walkFileTree(dir, DEFAULT_FILE_VISIT_OPTIONS, Integer.MAX_VALUE, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(final Path f, final BasicFileAttributes attrs) throws IOException { Files.delete(f); return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(final Path d, final IOException exc) throws IOException { if (exc != null) { throw exc; } else if (dir != d) { Files.delete(d); } return FileVisitResult.CONTINUE; } } ); } }
DirectoryHelper { public static void empty(final Path dir) throws IOException { validateDirectory(dir); Files.walkFileTree(dir, DEFAULT_FILE_VISIT_OPTIONS, Integer.MAX_VALUE, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(final Path f, final BasicFileAttributes attrs) throws IOException { Files.delete(f); return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(final Path d, final IOException exc) throws IOException { if (exc != null) { throw exc; } else if (dir != d) { Files.delete(d); } return FileVisitResult.CONTINUE; } } ); } private  DirectoryHelper(); }
DirectoryHelper { public static void empty(final Path dir) throws IOException { validateDirectory(dir); Files.walkFileTree(dir, DEFAULT_FILE_VISIT_OPTIONS, Integer.MAX_VALUE, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(final Path f, final BasicFileAttributes attrs) throws IOException { Files.delete(f); return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(final Path d, final IOException exc) throws IOException { if (exc != null) { throw exc; } else if (dir != d) { Files.delete(d); } return FileVisitResult.CONTINUE; } } ); } 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); }
DirectoryHelper { public static void empty(final Path dir) throws IOException { validateDirectory(dir); Files.walkFileTree(dir, DEFAULT_FILE_VISIT_OPTIONS, Integer.MAX_VALUE, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(final Path f, final BasicFileAttributes attrs) throws IOException { Files.delete(f); return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(final Path d, final IOException exc) throws IOException { if (exc != null) { throw exc; } else if (dir != d) { Files.delete(d); } return FileVisitResult.CONTINUE; } } ); } 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; }