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

booleanrecursiveDeleteNoCheck(File f)
recursive Delete No Check
try {
    if (f.isDirectory()) {
        File[] files = f.listFiles();
        for (int i = 0; i < files.length; i++) {
            if (!recursiveDeleteNoCheck(files[i])) {
                return (false);
        if (!f.delete()) {
            return (false);
    } else {
        if (!f.delete()) {
            return (false);
} catch (Exception ignore) {
return (true);
booleanrecursiveDeleteNoCheck(File f)
recursive Delete No Check
try {
    if (f.isDirectory()) {
        File[] files = f.listFiles();
        for (int i = 0; i < files.length; i++) {
            if (!recursiveDeleteNoCheck(files[i])) {
                return (false);
        if (!f.delete()) {
            return (false);
    } else {
        if (!f.delete()) {
            return (false);
} catch (Exception ignore) {
return (true);
voidrecursiveDeleteOnExit(File parent)
Recursively delete parent folder on exit of JVM
parent.deleteOnExit();
if (parent.isDirectory()) {
    File[] files = parent.listFiles();
    for (int ifile = 0; ifile < files.length; ++ifile) {
        if (files[ifile].isDirectory()) {
            recursiveDeleteOnExit(files[ifile]);
        files[ifile].deleteOnExit();
...
voidrecursiveDeleteOnExit(File rootDir)
Recursively set this directory to be deleted on termination of the JVM (using File#deleteOnExit() ).
recursiveDeleteOnExitHelper(rootDir);
voidrecursiveDeleteOnExitHelper(File fileOrDir)
recursive Delete On Exit Helper
fileOrDir.deleteOnExit();
if (fileOrDir.isDirectory()) {
    for (File file : fileOrDir.listFiles()) {
        recursiveDeleteOnExitHelper(file);
voidrecursivelyDelete(File aDirectory)
Recursively deletes the given directory and all of its nested contents.
if (!aDirectory.isDirectory()) {
    return;
File[] files = aDirectory.listFiles();
if (files != null) {
    for (File file : files) {
        if (file.isFile()) {
            file.delete();
...
voidrecursivelyDelete(File dir)
recursively Delete
if (!dir.getPath().equals(dir.getCanonicalPath())) {
    return;
File[] contents = dir.listFiles();
if (contents != null) {
    for (File d : contents) {
        if (d.isDirectory()) {
            recursivelyDelete(d);
...
voidrecursivelyDelete(final File root, final boolean deleteRoot)
Recursively deletes the contents of the given directory (and possibly the directory itself).
if (root.isDirectory()) {
    final File[] contents = root.listFiles();
    for (final File child : contents) {
        recursivelyDelete(child, true);
if (deleteRoot) {
    if (!root.delete()) {
...
voidrecursivelyDelete(String loc)
recursively Delete
recursivelyDelete(new File(loc));
voidrecursivelyDeleteEmptyDirectories(File fileToDelete)
recursively Delete Empty Directories
if (fileToDelete.isDirectory()) {
    for (File subFile : fileToDelete.listFiles()) {
        recursivelyDeleteEmptyDirectories(subFile);
    if (fileToDelete.listFiles().length == 0) {
        fileToDelete.delete();