Java Utililty Methods Delete Directory Recursively

List of utility methods to do Delete Directory Recursively

Description

The list of methods to do Delete Directory Recursively are organized into topic(s).

Method

voiddeleteDirectoryRecursive(File directory)
delete Directory Recursive
synchronized (EXMUT) {
    if (!directory.exists()) {
        return;
    if (!directory.isDirectory()) {
        throw new IllegalArgumentException("The passed file is not a directory (" + directory + ").");
    if (!directory.exists()) {
...
voiddeleteDirectoryRecursive(File f)
Delete a directory and all of it's contents in a depth-first recursive manner.
if (f.isDirectory()) {
    for (File c : f.listFiles()) {
        deleteDirectoryRecursive(c);
delete(f);
voiddeleteDirectoryRecursively(File rootFile)
Recursive function to delete Directory having content.
File[] files = rootFile.listFiles();
if (files != null) {
    for (File file : files) {
        if (file.isFile()) {
            file.delete();
        } else if (file.isDirectory()) {
            deleteDirectoryRecursively(file);
rootFile.delete();
voiddeleteDirectoryRecursively(File toDelete)
Delete file or empty and nonempty directory.
if (toDelete != null) {
    if (toDelete.isDirectory()) {
        File[] sub = toDelete.listFiles();
        if (sub != null && sub.length > 0) {
            for (File f : sub) {
                deleteDirectoryRecursively(f);
    toDelete.delete();
voiddeleteDirectoryRecursivelyE(File dir)
delete Directory Recursively E
if (!dir.isDirectory())
    throw new RuntimeException("Not a directory: " + dir.getAbsolutePath());
for (File f : dir.listFiles()) {
    if (f.isDirectory()) {
        deleteDirectoryRecursivelyE(f);
    } else {
        if (!f.delete())
            throw new RuntimeException("Failed to delete file: " + f.getAbsolutePath());
...
booleandeleteDirectoryRecursivly(File directory)
delete Directory Recursivly
String[] list = directory.list();
if (list != null) {
    for (String entryName : list) {
        File entry = new File(directory, entryName);
        if (entry.isDirectory()) {
            if (!deleteDirectoryRecursivly(entry)) {
                return false;
        } else {
            if (!entry.delete()) {
                return false;
if (!directory.delete()) {
    return false;
return true;
voiddeleteDirRecursive(File aDir)
delete Dir Recursive
if (!aDir.exists())
    return;
if (aDir.isDirectory()) {
    File[] files = aDir.listFiles();
    for (int i = 0; i < files.length; i++) {
        deleteDirRecursive(files[i]);
aDir.delete();
booleandeleteDirRecursively(File dir)
Given a filepath, delete all files in the directory recursively
if (dir.isDirectory()) {
    for (File f : dir.listFiles()) {
        boolean success = deleteDirRecursively(f);
        if (!success)
            return false;
return dir.delete();
...
booleandeleteDirRecursively(File directory)
This method deletes the directory, all files and all subdirectories under it.
String dirName = "";
boolean success = true;
if (directory.exists()) {
    if (directory.isDirectory()) {
        dirName = directory.getName();
        File[] children = directory.listFiles();
        for (File element : children) {
            if (element.isFile()) {
...