Java Utililty Methods Delete Empty Directory

List of utility methods to do Delete Empty Directory

Description

The list of methods to do Delete Empty Directory are organized into topic(s).

Method

booleandeleteEmptyFolders(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;
voiddeleteEmptyFolders(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())
...
voiddeleteEmptyParentFolders(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();
voiddeleteEmptyParents(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);