@Test public void doesNotDeleteFilesWhenDeletingEmptyDirs() throws IOException { Path emptyDir1 = _tempFolder.newFolder("level_1_dir_1", "level_2_dir_1", "level_3_dir_1").toPath(); Path emptyDir2 = _tempFolder.newFolder("level_1_dir_1", "level_2_dir_1", "level_3_dir_2", "level_4_dir_1").toPath(); _tempFolder.newFolder("level_1_dir_1", "level_2_dir_2"); Path emptyDir3 = _tempFolder.newFolder("level_1_dir_2").toPath(); Path file1 = _tempFolder.newFile("level_1_dir_1/level_2_dir_1/level_3_dir_2/file1").toPath(); Path file2 = _tempFolder.newFile("level_1_dir_1/level_2_dir_2/file2").toPath(); IoUtils.deleteEmptyDirectoriesRecursively(_tempRoot); assertTrue(Files.exists(file1)); assertTrue(Files.exists(file2)); assertFalse(Files.exists(emptyDir1)); assertFalse(Files.exists(emptyDir2)); assertFalse(Files.exists(emptyDir3)); }
public static void deleteEmptyDirectoriesRecursively(Path startDir) { if (!Files.exists(startDir)) { return; } try { Files.walkFileTree(startDir, new SimpleFileVisitor<Path>() { public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { if (isEmpty(dir)) { Files.delete(dir); } return FileVisitResult.CONTINUE; } }); } catch (IOException e) { log.warn("IOException while deleting " + startDir, e); } }
IoUtils { public static void deleteEmptyDirectoriesRecursively(Path startDir) { if (!Files.exists(startDir)) { return; } try { Files.walkFileTree(startDir, new SimpleFileVisitor<Path>() { public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { if (isEmpty(dir)) { Files.delete(dir); } return FileVisitResult.CONTINUE; } }); } catch (IOException e) { log.warn("IOException while deleting " + startDir, e); } } }
IoUtils { public static void deleteEmptyDirectoriesRecursively(Path startDir) { if (!Files.exists(startDir)) { return; } try { Files.walkFileTree(startDir, new SimpleFileVisitor<Path>() { public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { if (isEmpty(dir)) { Files.delete(dir); } return FileVisitResult.CONTINUE; } }); } catch (IOException e) { log.warn("IOException while deleting " + startDir, e); } }  }
IoUtils { public static void deleteEmptyDirectoriesRecursively(Path startDir) { if (!Files.exists(startDir)) { return; } try { Files.walkFileTree(startDir, new SimpleFileVisitor<Path>() { public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { if (isEmpty(dir)) { Files.delete(dir); } return FileVisitResult.CONTINUE; } }); } catch (IOException e) { log.warn("IOException while deleting " + startDir, e); } }  String getMimeType(URL url); String getMimeType(String absolutePath); String getMimeType(byte[] bytes); String getMimeType(File file); String getMimeType(Path path); String getMimeType(InputStream inputStream); MediaType getMediaTypeFromMimeType(String mimeType); MediaType getMediaType(URL url); URI findFile(String path); File getNewFileName(String directory, String filename); boolean isApprovedFile(File file); boolean isApprovedFile(URL url); boolean isApprovedContentType(String contentType); static void closeQuietly(Closeable closeable); static Optional<Path> toLocalPath(String pathOrUri); static URL toUrl(String pathOrUri); static InputStream openStream(String pathOrUri); static void deleteEmptyDirectoriesRecursively(Path startDir); static void writeFileAsAttachment(Path path, HttpServletResponse response); static void writeContentAsAttachment(
            InputStream inputStream,
            HttpServletResponse response,
            String fileName,
            String mimeType,
            long contentLength); static String normalizeUri(String uriString); }
IoUtils { public static void deleteEmptyDirectoriesRecursively(Path startDir) { if (!Files.exists(startDir)) { return; } try { Files.walkFileTree(startDir, new SimpleFileVisitor<Path>() { public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { if (isEmpty(dir)) { Files.delete(dir); } return FileVisitResult.CONTINUE; } }); } catch (IOException e) { log.warn("IOException while deleting " + startDir, e); } }  String getMimeType(URL url); String getMimeType(String absolutePath); String getMimeType(byte[] bytes); String getMimeType(File file); String getMimeType(Path path); String getMimeType(InputStream inputStream); MediaType getMediaTypeFromMimeType(String mimeType); MediaType getMediaType(URL url); URI findFile(String path); File getNewFileName(String directory, String filename); boolean isApprovedFile(File file); boolean isApprovedFile(URL url); boolean isApprovedContentType(String contentType); static void closeQuietly(Closeable closeable); static Optional<Path> toLocalPath(String pathOrUri); static URL toUrl(String pathOrUri); static InputStream openStream(String pathOrUri); static void deleteEmptyDirectoriesRecursively(Path startDir); static void writeFileAsAttachment(Path path, HttpServletResponse response); static void writeContentAsAttachment(
            InputStream inputStream,
            HttpServletResponse response,
            String fileName,
            String mimeType,
            long contentLength); static String normalizeUri(String uriString); static final String REF; }