Java Delete Empty Directory deleteEmptyFolders(String[] args)

Here you can find the source of deleteEmptyFolders(String[] args)

Description

delete Empty Folders

License

Open Source License

Declaration

public static void deleteEmptyFolders(String[] args) 

Method Source Code

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

import java.io.File;

import java.util.Stack;

public class Main {
    static File base = new File(
            "D:/Thesis test results/thesisSimple/imageOutput/UB72");

    public static void deleteEmptyFolders(String[] args) {

        Stack<File[]> dfs = new Stack<File[]>();
        dfs.add(base.listFiles());/*from w w  w .j av  a2 s  .  co m*/

        while (!dfs.isEmpty()) {
            File[] subFiles = dfs.pop();
            if (subFiles == null)
                continue;

            for (File subFolder : subFiles) {
                if (!subFolder.isDirectory())
                    continue;

                try {
                    subFolder.delete();
                } catch (Exception e) {
                }
                ;

                dfs.add(subFolder.listFiles());

            }
        }
    }
}

Related

  1. deleteEmptyDirectoryRecursive(File directory)
  2. deleteEmptyDirs(File dir)
  3. deleteEmptyDirs(File dir)
  4. deleteEmptyFiles(String p)
  5. deleteEmptyFolders(java.io.File file)
  6. deleteEmptyParentFolders(File leafFolder)
  7. deleteEmptyParents(File currentParentFile, String inputDir)