Java Delete File Recursively deleteRecursively(File[] roots)

Here you can find the source of deleteRecursively(File[] roots)

Description

Delete recursively.

License

Open Source License

Parameter

Parameter Description
roots the roots

Return

true, if successful

Declaration

public static boolean deleteRecursively(File[] roots) 

Method Source Code


//package com.java2s;
import java.io.File;

public class Main {
    /**/*from w w w .  ja  v  a  2 s.co m*/
     * Delete recursively.
     *
     * @param roots the roots
     * @return true, if successful
     */
    public static boolean deleteRecursively(File[] roots) {
        boolean deleted = true;
        for (File root : roots) {
            deleted &= deleteRecursively(root);
        }
        return deleted;
    }

    /**
     * Delete recursively.
     *
     * @param root the root
     * @return true, if successful
     */
    public static boolean deleteRecursively(File root) {
        return deleteRecursively(root, true);
    }

    /**
     * Delete recursively.
     *
     * @param root the root
     * @param deleteRoot the delete root
     * @return true, if successful
     */
    public static boolean deleteRecursively(File root, boolean deleteRoot) {
        if (root != null && root.exists()) {
            if (root.isDirectory()) {
                File[] children = root.listFiles();
                if (children != null) {
                    for (File aChildren : children) {
                        innerDeleteRecursively(aChildren);
                    }
                }
            }

            if (deleteRoot) {
                return root.delete();
            } else {
                return true;
            }
        }
        return false;
    }

    /**
     * Inner delete recursively.
     *
     * @param root the root
     * @return true, if successful
     */
    private static boolean innerDeleteRecursively(File root) {
        return deleteRecursively(root, true);
    }
}

Related

  1. deleteRecursively(File fRoot)
  2. deleteRecursively(File name)
  3. deleteRecursively(File root)
  4. deleteRecursively(File root)
  5. deleteRecursively(File root, boolean deleteRoot)
  6. deleteRecursively(final File directory)
  7. deleteRecursively(final File directory)
  8. deleteRecursively(final File iRootFile)
  9. deleteRecursivelyAtLeastOnExit(final File directory)