Java Recursive Delete recursivelyDeleteEmptyDirectories(File fileToDelete)

Here you can find the source of recursivelyDeleteEmptyDirectories(File fileToDelete)

Description

recursively Delete Empty Directories

License

LGPL

Declaration

public static void recursivelyDeleteEmptyDirectories(File fileToDelete) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.io.*;

public class Main {
    public static void recursivelyDeleteEmptyDirectories(File fileToDelete) {
        if (fileToDelete.isDirectory()) {
            for (File subFile : fileToDelete.listFiles()) {
                recursivelyDeleteEmptyDirectories(subFile);
            }// w w  w  .j  av a2 s . c o  m

            if (fileToDelete.listFiles().length == 0) {
                fileToDelete.delete();
            }
        }
    }
}

Related

  1. recursiveDeleteOnExitHelper(File fileOrDir)
  2. recursivelyDelete(File aDirectory)
  3. recursivelyDelete(File dir)
  4. recursivelyDelete(final File root, final boolean deleteRoot)
  5. recursivelyDelete(String loc)
  6. recursivelyDeleteEmptyParentDirectoriesUpToRoot(String path, String root)
  7. recursivelyDeleteFile(File path)
  8. recursiveRemoveDir(File dir)
  9. recursiveRemoveDir(File directory)