List of utility methods to do Path Delete nio
void | delete(Path targetPath) delete Files.delete(targetPath); |
void | delete(Path... paths) Deletes all given Paths recursively. for (Path path : paths) { if (!Files.exists(path)) { continue; List<Path> childPaths = collect(path); Collections.reverse(childPaths); for (Path childPath : childPaths) { Files.delete(childPath); ... |
void | delete(String filePath, String fileName) delete Path fileToDeletePath = Paths.get(filePath + File.separator + fileName); boolean existsFile = fileToDeletePath.toFile().exists(); if (existsFile) { Files.delete(fileToDeletePath); |
void | delete(String targetFilePath) delete Path path = Paths.get(targetFilePath); Files.deleteIfExists(path); |
int | deleteAllFilesRecursively(Path path) delete All Files Recursively return deleteFilesRecursively(path, ALL_FILES);
|
void | deleteContent(Path directory) delete Content Files.walkFileTree(directory, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.delete(file); return FileVisitResult.CONTINUE; }); |
void | deleteEmptyDirsUpTo(Path from, Path to) delete Empty Dirs Up To Path pathsInBetween = to.relativize(from); for (int i = pathsInBetween.getNameCount(); i > 0; i--) { Path toRemove = to.resolve(pathsInBetween.subpath(0, i)); if (Files.list(toRemove).findAny().isPresent()) { return; } else { Files.delete(toRemove); |
void | deleteEmptyParentDirs(Path pkgDirPath, Path repoPath) Delete empty parent directories. Path pathsInBetween = repoPath.relativize(pkgDirPath); for (int i = pathsInBetween.getNameCount(); i > 0; i--) { Path toRemove = repoPath.resolve(pathsInBetween.subpath(0, i)); if (!Files.list(toRemove).findAny().isPresent()) { Files.delete(toRemove); |
void | deleteFile(Path p) delete File try { Files.deleteIfExists(p); } catch (IOException e) { throw new RuntimeException(e); |
void | deleteFile(Path path) Deletes a file if it exists. if (!isFolder(path)) {
Files.deleteIfExists(path);
|