Java Recursive Delete recursivelyDelete(File aDirectory)

Here you can find the source of recursivelyDelete(File aDirectory)

Description

Recursively deletes the given directory and all of its nested contents.

License

Open Source License

Parameter

Parameter Description
aDirectory a parameter

Declaration

public static void recursivelyDelete(File aDirectory) 

Method Source Code

//package com.java2s;
import java.io.*;

public class Main {
    /**//from ww  w.  ja v  a  2 s .c o m
     * Recursively deletes the given directory and all of
     * its nested contents. Use carefully!
     *
     * @param aDirectory
     */
    public static void recursivelyDelete(File aDirectory) {
        if (!aDirectory.isDirectory()) {
            return;
        }

        File[] files = aDirectory.listFiles();

        if (files != null) {
            for (File file : files) {
                if (file.isFile()) {
                    file.delete();
                } else {
                    recursivelyDelete(file);
                }
            }
        }
        aDirectory.delete();
    }
}

Related

  1. recursiveDeleteNoCheck(File f)
  2. recursiveDeleteNoCheck(File f)
  3. recursiveDeleteOnExit(File parent)
  4. recursiveDeleteOnExit(File rootDir)
  5. recursiveDeleteOnExitHelper(File fileOrDir)
  6. recursivelyDelete(File dir)
  7. recursivelyDelete(final File root, final boolean deleteRoot)
  8. recursivelyDelete(String loc)
  9. recursivelyDeleteEmptyDirectories(File fileToDelete)