List of utility methods to do Folder Delete nio
void | delete(Path folder, List delete delete(folder, folder, noDeleteFiles); |
void | deleteEmptyFolder(String... dirNames) delete Empty Folder File dir = generateFileObject(dirNames); System.out.println("Deleting folder '" + dir + "'"); try { Files.delete(dir.toPath()); } catch (IOException e) { throw new Exception( e.getClass().getSimpleName() + " deleting empty folder '" + dir + "' : " + e.getMessage()); |
boolean | deleteFile(String folderName, String fileName) delete File Path filePath = Paths.get(folderName, fileName); boolean deleted = Files.deleteIfExists(filePath); return deleted; |
void | deleteFolder(Path folder) delete Folder if (folder.toFile().exists() && folder.toFile().isDirectory()) { System.out.println("deleting " + folder.toAbsolutePath()); deleteRecursive(folder.toFile()); |
void | deleteFolder(Path path) Deletes a directory if it exists. deleteFolder(path, true); |
void | deleteFolderAndSubfolders(Path pathToFile) Delete folder and all subcontents. File f = pathToFile.toFile(); File[] currentFileList; Stack<File> stack = new Stack<>(); stack.push(f); while (!stack.isEmpty()) { if (stack.lastElement().isDirectory()) { currentFileList = stack.lastElement().listFiles(); if (currentFileList.length > 0) { ... |
void | deleteRecursively(File folder) Recursively deletes a folder and all its content Files.walkFileTree(folder.toPath(), new SimpleFileVisitor<Path>() { @Override public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException { if (e == null) { Files.delete(dir); return FileVisitResult.CONTINUE; } else { throw e; ... |