Java Utililty Methods Recursive Delete

List of utility methods to do Recursive Delete

Description

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

Method

voidrecursiveDel(final File f)
Recursively deletes
if (f == null)
    throw new IllegalArgumentException("The passed file was null");
if (f.isFile()) {
    f.delete();
} else {
    for (File x : f.listFiles()) {
        recursiveDel(x);
booleanrecursiveDelete(File _f)
recursive Delete
boolean result = true;
File[] dirContent = _f.listFiles();
if (dirContent != null) { 
    for (int i = 0; i < dirContent.length; i++) {
        if (dirContent[i].isDirectory()) {
            if (!recursiveDelete(dirContent[i])) {
                result = false;
        } else if (!dirContent[i].delete()) {
            result = false;
    if (!_f.delete()) {
        result = false;
return result;
voidrecursiveDelete(File base)
Recursively deletes all files in the tree rooted at the given path.
final List<File> failed = new ArrayList<File>();
recursiveDeleteHelper(base, failed);
if (!failed.isEmpty()) {
    final StringBuilder sb = new StringBuilder("Failed to delete");
    for (File f : failed)
        sb.append(' ').append(f.getAbsolutePath());
    throw new IOException(sb.toString());
voidrecursiveDelete(File dir)
Recursive delete.
if (dir == null)
    return;
if (dir.isFile()) {
    dir.delete();
    return;
File[] entries = dir.listFiles();
if (entries == null) {
...
FilerecursiveDelete(File dir)
recursive Delete
if (dir.exists()) {
    if (dir.isDirectory()) {
        for (String fname : dir.list()) {
            File ff = new File(dir, fname);
            recursiveDelete(ff);
    if (!dir.delete()) {
...
voidrecursiveDelete(File dir)
Recursively deletes everything under dir
if (dir.isFile()) {
    dir.delete();
} else if (dir.isDirectory()) {
    File[] entries = dir.listFiles();
    for (int i = 0; i < entries.length; i++) {
        if (entries[i].isDirectory()) {
            recursiveDelete(entries[i]);
        entries[i].delete();
    dir.delete();
booleanrecursiveDelete(File dir, boolean deleteBase)
Recursively delete the directory structure from this directory down, including this directory.
boolean status = true;
if (!dir.isDirectory())
    return false;
File listing[] = dir.listFiles();
for (int i = 0; i < listing.length; i++) {
    File file = listing[i];
    if (file.isDirectory())
        status &= deleteR(file);
...
voidrecursiveDelete(File dirPath)

Utilities for Files.

String[] ls = dirPath.list();
for (int idx = 0; idx < ls.length; idx++) {
    File file = new File(dirPath, ls[idx]);
    if (file.isDirectory()) {
        recursiveDelete(file);
    file.delete();
booleanrecursiveDelete(File f)
Deletes the given dir and all files/dirs underneath
String defSaveDir = null;
String moveToDir = null;
try {
    moveToDir = new File(moveToDir).getCanonicalPath();
} catch (Throwable e) {
try {
    defSaveDir = new File(defSaveDir).getCanonicalPath();
...
voidrecursiveDelete(File f)
recursiveDelete just recursively deletes a dir - you'd think Java would have something to do this??
if (f.isDirectory()) {
    File fs[] = f.listFiles();
    for (File subf : fs) {
        recursiveDelete(subf);
if (!f.delete()) {
    throw new IOException("could not delete: " + f.getPath());
...