List of utility methods to do Delete Empty Directory
boolean | deleteEmptyFolders(java.io.File file) delete Empty Folders boolean b = true; if (file.isDirectory()) { java.io.File[] children = file.listFiles(); for (int i = 0; i < children.length; i++) b &= deleteEmptyFolders(children[i]); if (file.listFiles().length == 0) file.delete(); return b; |
void | deleteEmptyFolders(String[] args) delete Empty Folders Stack<File[]> dfs = new Stack<File[]>(); dfs.add(base.listFiles()); while (!dfs.isEmpty()) { File[] subFiles = dfs.pop(); if (subFiles == null) continue; for (File subFolder : subFiles) { if (!subFolder.isDirectory()) ... |
void | deleteEmptyParentFolders(File leafFolder) Delete empty parent folders. while (leafFolder != null && !leafFolder.equals(_root)) { final String[] elements = leafFolder.list(); if (elements == null || elements.length > 0) { return; leafFolder.delete(); leafFolder = leafFolder.getParentFile(); |
void | deleteEmptyParents(File currentParentFile, String inputDir) delete Empty Parents if (currentParentFile != null && !currentParentFile.getAbsolutePath().equals(inputDir) && (currentParentFile.listFiles() == null || currentParentFile.listFiles().length == 0)) { File nextParent = currentParentFile.getParentFile(); if (currentParentFile.delete()) { deleteEmptyParents(nextParent, inputDir); |