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

booleanrecursiveDelete(File parent)
recursive Delete
if (parent.exists()) {
    if (parent.isDirectory()) {
        File[] files = parent.listFiles();
        for (int ifile = 0; ifile < files.length; ++ifile) {
            if (files[ifile].isDirectory()) {
                recursiveDelete(files[ifile]);
            if (files[ifile].exists()) {
...
booleanrecursiveDelete(File pathToFolderOrFile)
Deletes file or folder.
if (pathToFolderOrFile.isFile() && pathToFolderOrFile.exists()) {
    pathToFolderOrFile.delete();
} else if (pathToFolderOrFile.exists()) {
    File[] files = pathToFolderOrFile.listFiles();
    for (int i = 0; i < files.length; i++) {
        if (files[i].isDirectory()) {
            recursiveDelete(files[i]);
        } else {
...
voidrecursiveDelete(File root)
Recursively delete a file and all its contents.
if (root == null) {
    return;
if (root.isDirectory()) {
    File[] files = root.listFiles();
    if (files != null) {
        for (int i = 0; i < files.length; i++) {
            File file = files[i];
...
booleanrecursiveDelete(File root)
recursive Delete
if (root == null) {
    return true;
boolean ok = true;
if (root.isDirectory()) {
    final File[] files = root.listFiles();
    for (File file : files) {
        ok &= recursiveDelete(file);
...
voidrecursiveDelete(File rootDir, boolean deleteRoot)
recursive Delete
if ((rootDir == null) || !rootDir.isDirectory()) {
    return;
File[] childDirs = rootDir.listFiles();
if (childDirs != null) {
    for (File f : childDirs) {
        if (f.isDirectory()) {
            recursiveDelete(f, false);
...
booleanrecursiveDelete(File target)
recursive Delete
if (target.isDirectory()) {
    for (File f : target.listFiles())
        recursiveDelete(f);
return target.delete();
voidrecursiveDelete(final File directory)
Little test utility to help tests that create multiple levels of subdirectories clean up after themselves.
for (final File f : directory.listFiles()) {
    if (f.isDirectory()) {
        recursiveDelete(f);
    f.delete();
voidrecursiveDelete(final File file, final boolean childrenOnly)
Deletes a file or recursively deletes a directory.
recursiveDelete(file, childrenOnly, null);
booleanrecursiveDelete(final File fileOrDir)
Recursively delete file or directory
if (fileOrDir == null) {
    return false;
if (fileOrDir.isDirectory()) {
    for (File innerFile : fileOrDir.listFiles()) {
        if (!recursiveDelete(innerFile)) {
            return false;
return fileOrDir.delete();
booleanrecursiveDelete(final File path)
Recursively delete the given path, stopping on the first error.
if (path.isDirectory()) {
    String[] children = path.list();
    if (children == null) {
        return false;
    for (int i = 0; i < children.length; i++) {
        if (!recursiveDelete(new File(path, children[i]))) {
            return false;
...