Java Delete Empty Directory deleteEmptyParents(File currentParentFile, String inputDir)

Here you can find the source of deleteEmptyParents(File currentParentFile, String inputDir)

Description

delete Empty Parents

License

Open Source License

Declaration

public static void deleteEmptyParents(File currentParentFile, String inputDir) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.File;

public class Main {
    public static void deleteEmptyParents(File currentParentFile, String inputDir) {
        if (currentParentFile != null && !currentParentFile.getAbsolutePath().equals(inputDir)
                && (currentParentFile.listFiles() == null || currentParentFile.listFiles().length == 0)) {
            File nextParent = currentParentFile.getParentFile();
            if (currentParentFile.delete()) {
                deleteEmptyParents(nextParent, inputDir);
            }//w  w w  .j  a  v  a 2  s.  c  om
        }
    }
}

Related

  1. deleteEmptyDirs(File dir)
  2. deleteEmptyFiles(String p)
  3. deleteEmptyFolders(java.io.File file)
  4. deleteEmptyFolders(String[] args)
  5. deleteEmptyParentFolders(File leafFolder)