Java Utililty Methods Delete Directory

List of utility methods to do Delete Directory

Description

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

Method

booleandeleteDirectory(File dir)
Deletes a directory and all of its contents.
boolean retval = true;
File[] currList;
Stack<File> stack = new Stack<File>();
stack.push(dir);
while (!stack.isEmpty()) {
    if (stack.lastElement().isDirectory()) {
        currList = stack.lastElement().listFiles();
        if (currList.length > 0) {
...
voiddeleteDirectory(File dir)
delete Directory
if (dir.isDirectory()) {
    for (File f : dir.listFiles()) {
        if (f.isDirectory())
            deleteDirectory(f);
        else
            f.delete();
    dir.delete();
...
voiddeleteDirectory(File dir)
delete Directory
deleteDirectory(dir, false);
booleandeleteDirectory(File dir)
delete Directory
if (dir != null && dir.exists()) {
    File[] a = dir.listFiles();
    for (int i = 0; a != null && i < a.length; i++) {
        if (a[i].isDirectory()) {
            deleteDirectory(a[i]);
        } else {
            a[i].delete();
    return dir.delete();
return true;
voiddeleteDirectory(File dir)
Deletes a directory with all its files and subdirectories.
if (!dir.exists()) {
    return;
if (!dir.isDirectory()) {
    throw new IOException("File is not a directory: " + dir.getAbsolutePath());
File[] fileArr = dir.listFiles();
if (fileArr != null) {
...
booleandeleteDirectory(File dir)
Deletes dir and all files and subdirectories under dir.
return deleteDirectory(dir, null);
booleandeleteDirectory(File dir, boolean isInitialDelete)
delete Directory
if (dir.isDirectory()) {
    if (dir.exists()) {
        for (File child : dir.listFiles()) {
            try {
                deleteDirectory(child, isInitialDelete);
            } catch (Exception e) {
                if (isInitialDelete)
                    continue;
...
booleandeleteDirectory(File dir, boolean isInitialDelete)
Utility method for delete directory
if (dir.isDirectory()) {
    if (dir.exists()) {
        for (File child : dir.listFiles()) {
            try {
                deleteDirectory(child, isInitialDelete);
            } catch (Exception e) {
                if (isInitialDelete) {
                    continue;
...
voiddeleteDirectory(File dir, boolean recursive)
deletes all files in a director
if (!dir.isDirectory())
    throw new IllegalArgumentException("directory expected");
File[] files = dir.listFiles();
for (int i = 0; i < files.length; i++) {
    if (files[i].isDirectory() && recursive)
        deleteDirectory(files[i], true);
    files[i].delete();
booleandeleteDirectory(File dir, Map preserve)
Recursively deletes a directory
if (dir == null || !dir.exists()) {
    return true;
File[] files = dir.listFiles();
boolean deletedAll = true;
for (int i = 0; i < files.length; i++) {
    if (preserve != null) {
        if (preserve.containsKey(normalizeFileName(files[i]))) {
...