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

voidrecursiveDelete(File file)
Utility routine to recurisvely delete a directory.
file = file.getAbsoluteFile();
if (!file.exists())
    return;
if (file.isDirectory()) {
    for (File child : file.listFiles()) {
        recursiveDelete(child);
if (!file.delete()) {
    throw new RuntimeException("Failed to delete " + file);
voidrecursiveDelete(File file)
Recursivelly delete a file or directory
if (file != null) {
    if (file.isDirectory()) {
        for (File subFile : file.listFiles()) {
            recursiveDelete(subFile);
    if (!file.delete()) {
        Logger.global.info("Could not delete file " + file);
...
booleanrecursiveDelete(File file)
Recursively deletes a file/folder structure.
System.gc();
if (file.isDirectory()) {
    boolean ret = true;
    for (File f : file.listFiles()) {
        if (!recursiveDelete(f)) {
            ret = false;
    if (!file.delete()) {
        ret = false;
    return ret;
} else {
    return file.delete();
booleanrecursiveDelete(File file)
Delete a file and all its descendants, indicating success or failure.
boolean success = true;
if (file.isDirectory()) {
    for (File child : file.listFiles()) {
        if (!recursiveDelete(child)) {
            success = false;
if (!file.delete()) {
    success = false;
return success;
booleanrecursiveDelete(File file)
Attempts to delete the specified file or directory.
if (file.exists()) {
    boolean successful = true;
    if (file.isDirectory()) {
        File[] childList = file.listFiles();
        if (childList != null) {
            for (File f : childList) {
                successful &= recursiveDelete(f);
    return successful & file.delete();
return false;
intrecursiveDelete(File file)
Recursively deletes the given file whether its a file or directory returning the number of files deleted
int answer = 0;
if (file.isDirectory()) {
    File[] files = file.listFiles();
    if (files != null) {
        for (File child : files) {
            answer += recursiveDelete(child);
if (file.delete()) {
    answer += 1;
return answer;
voidrecursiveDelete(File file, boolean deleteParentFile)
Recursively deletes a file (folder) and all children
File[] files = file.listFiles();
for (int i = 0; i < files.length; i++) {
    File file1 = files[i];
    if (file1.isDirectory()) {
        recursiveDelete(file1);
    } else {
        file1.delete();
if (deleteParentFile) {
    file.delete();
voidrecursiveDelete(File fileOrDir)
Recursively delete a directory.
if (fileOrDir.isDirectory()) {
    File[] contents = fileOrDir.listFiles();
    if (contents != null && contents.length > 0) {
        for (int x = 0; x < contents.length; x++) {
            File entry = contents[x];
            recursiveDelete(entry);
if (!fileOrDir.delete()) {
    throw new IllegalStateException(fileOrDir.getAbsolutePath() + " delete returned false!");
booleanrecursiveDelete(File fileOrDir)
recursive Delete
if (!fileOrDir.exists()) {
    System.err.println("delete: no such file or directory: " + fileOrDir.getPath());
    return false;
if (fileOrDir.isDirectory()) {
    for (File innerFile : fileOrDir.listFiles()) {
        if (!recursiveDelete(innerFile)) {
            return false;
...
booleanrecursiveDelete(File folder)
fully delete a folder
boolean ret = _recursiveDelete(folder);
clean();
return ret;