List of utility methods to do Delete Empty Directory
boolean | deleteEmptyChildren(java.io.File file) delete Empty Children boolean b = true; if (file.isDirectory()) { java.io.File[] children = file.listFiles(); for (int i = 0; i < children.length; i++) b &= deleteEmptyFolders(children[i]); return b; |
boolean | deleteEmptyDir(File directory) delete Empty Dir if (directory.exists() && directory.isDirectory() && directory.list() != null && directory.list().length == 0) { return directory.delete(); return false; |
void | deleteEmptyDir(File file) delete Empty Dir if (!file.exists() || file.isFile()) { return; if (file.isDirectory()) { if (file.list().length == 0) { file.delete(); } else { for (File f : file.listFiles()) { ... |
int | deleteEmptyDirectories(List Deletes empty directories recursively. int dirsDeleted = 0; boolean success = false; File dir; for (Iterator<File> dirIter = dirs.iterator(); dirIter.hasNext();) { dir = dirIter.next(); if ((dir != null) && dir.exists() && (dir.list().length == 0)) { success = dir.delete(); if (success) { ... |
void | deleteEmptyDirectory(File fileOrDirectory) delete Empty Directory if (fileOrDirectory.isDirectory()) { if (fileOrDirectory.list().length == 0) { fileOrDirectory.delete(); |
void | deleteEmptyDirectoryRecursive(File directory) Deletes an empty directory, including all parent directories that are also empty, stopping at the first non-empty parent. if ((directory != null) && directory.isDirectory()) { File[] files = directory.listFiles(); if ((files == null) || (files.length == 0)) { if (!directory.delete()) throw new IOException("Could not delete empty directory: " + directory); deleteEmptyDirectoryRecursive(directory.getParentFile()); |
boolean | deleteEmptyDirectoryRecursive(File directory) delete Empty Directory Recursive String canonicalParent; try { canonicalParent = directory.getCanonicalPath(); } catch (IOException ioe) { return false; if (!directory.isDirectory()) { return false; ... |
void | deleteEmptyDirs(File dir) delete Empty Dirs File[] files = dir.listFiles(); if (files != null) { for (int i = 0; i < files.length; i += 1) { deleteEmptyDirs(files[i]); dir.getCanonicalFile().delete(); |
void | deleteEmptyDirs(File dir) Deletes all empty directories in a directory, but leaves the directory itself unmodified. File[] files = dir.listFiles(); if (files != null) { for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) { deleteEmptyDirs(files[i]); File[] subfiles = files[i].listFiles(); if (subfiles == null || subfiles.length == 0) { delete(files[i]); ... |
void | deleteEmptyFiles(String p) delete Empty Files File path = new File(p); File[] files = path.listFiles(); for (int i = 0; i < files.length; i++) { if (files[i].length() == 0) { files[i].delete(); |