Java Delete Directory Recursively deleteDirRecursively(File dir)

Here you can find the source of deleteDirRecursively(File dir)

Description

Given a filepath, delete all files in the directory recursively

License

Open Source License

Parameter

Parameter Description
dir a parameter

Return

true if the deletion is successful, false otherwise

Declaration

public static boolean deleteDirRecursively(File dir) 

Method Source Code


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

public class Main {
    /**//from   w ww.j a v a  2s.c om
     * Given a filepath, delete all files in the directory recursively
     * @param dir
     * @return {@code true} if the deletion is successful, {@code false} otherwise
     */
    public static boolean deleteDirRecursively(File dir) {
        if (dir.isDirectory()) {
            for (File f : dir.listFiles()) {
                boolean success = deleteDirRecursively(f);
                if (!success)
                    return false;
            }
        }
        return dir.delete();
    }
}

Related

  1. deleteDirectoryRecursively(File rootFile)
  2. deleteDirectoryRecursively(File toDelete)
  3. deleteDirectoryRecursivelyE(File dir)
  4. deleteDirectoryRecursivly(File directory)
  5. deleteDirRecursive(File aDir)
  6. deleteDirRecursively(File directory)