Java Utililty Methods Delete File Recursively

List of utility methods to do Delete File Recursively

Description

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

Method

booleandeleteRecursively(File[] roots)
Delete recursively.
boolean deleted = true;
for (File root : roots) {
    deleted &= deleteRecursively(root);
return deleted;
booleandeleteRecursively(final File directory)
Delete a directory recursively
if (directory == null) {
    return true;
final File[] list = directory.listFiles();
if (list == null) {
    return true;
for (final File file : list) {
...
voiddeleteRecursively(final File directory)
delete Recursively
final Stack<File> stack = new Stack<>();
final List<File> temp = new LinkedList<>();
stack.push(directory.getAbsoluteFile());
while (!stack.isEmpty()) {
    final File top = stack.pop();
    File[] files = top.listFiles();
    if (files != null) {
        for (final File child : files) {
...
voiddeleteRecursively(final File iRootFile)
delete Recursively
if (iRootFile.exists()) {
    if (iRootFile.isDirectory()) {
        for (File f : iRootFile.listFiles()) {
            if (f.isFile())
                f.delete();
            else
                deleteRecursively(f);
    iRootFile.delete();
booleandeleteRecursivelyAtLeastOnExit(final File directory)
Deletes a directory recursively, falling back to deleteOnExit().
boolean result = true;
final File[] list = directory.listFiles();
if (list != null) {
    for (final File file : list) {
        if (file.isDirectory()) {
            if (!deleteRecursivelyAtLeastOnExit(file)) {
                result = false;
            continue;
        if (!file.delete()) {
            file.deleteOnExit();
            result = false;
if (!result || !directory.delete()) {
    directory.deleteOnExit();
    result = false;
return result;
booleandeleteRecursivelyWithoutDeleteRootDirectory(File pFile)
delete Recursively Without Delete Root Directory
boolean result = true;
if (pFile.isDirectory()) {
    File files[] = pFile.listFiles();
    for (int i = 0; i < files.length; i++) {
        result &= deleteRecursively(files[i]);
return result;
...
booleandeleteRecusively(File file)
Delete the specified file.
if (file.isDirectory()) {
    File[] subfiles = file.listFiles();
    int nb = subfiles.length;
    for (int i = 0; i < nb; i++) {
        deleteRecusively(subfiles[i]);
return file.delete();
...