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(final File directory)
delete Directory
if (directory == null) {
    return false;
final File[] files = directory.listFiles();
for (int num = files.length, i = 0; i < num; ++i) {
    if (files[i].isDirectory()) {
        if (!deleteDirectory(files[i])) {
            return false;
...
booleandeleteDirectory(final File directory)
Delete a directory and its content
boolean success = true;
;
if (directory.exists()) {
    final File[] files = directory.listFiles();
    for (int i = 0; i < files.length; i++) {
        if (files[i].isDirectory()) {
            success &= deleteDirectory(files[i]);
        } else {
...
voiddeleteDirectory(final File directory)
Recursively deletes a directory and all its contents
if (directory.isDirectory() && directory.exists()) {
    for (File file : directory.listFiles()) {
        if (file.isDirectory()) {
            deleteDirectory(file);
        } else {
            if (!file.delete()) {
                throw new RuntimeException("Failed to delete file: " + file);
    if (!directory.delete()) {
        throw new RuntimeException("Failed to delete directory: " + directory);
} else {
    throw new RuntimeException("Unable to delete directory: " + directory
            + ".  It is either not a directory or does not exist.");
booleandeleteDirectory(final String dir)
delete Directory
return deleteDirectory(new File(dir));
voiddeleteDirectory(final String targetDir)
Delete a directory
final File file = new File(targetDir);
if (file.exists()) {
    if (file.isFile()) {
        file.delete();
    } else if (file.isDirectory()) {
        final File files[] = file.listFiles();
        for (int i = 0; i < files.length; i++) {
            final String dir = targetDir + File.separator + files[i].getName();
...
voiddeleteDirectory(IProgressMonitor monitor, File directory)
Recursively delete a directory.
if (!directory.exists()) {
    return;
cleanDirectory(monitor, directory);
if (!directory.delete()) {
    String message = "Unable to delete directory " + directory + ".";
    throw new IOException(message);
voiddeleteDirectory(IProgressMonitor monitor, File directory, File base, int step)
Recursively delete a directory.
if (!directory.exists()) {
    return;
cleanDirectory(monitor, directory, base, step);
if (!directory.delete()) {
    String message = "Unable to delete directory " + directory + "."; 
    throw new IOException(message);
booleandeleteDirectory(String dir)
delete Directory
return deleteDirectoryRecursively(new File(dir));
booleandeleteDirectory(String directory)
delete Directory
return deleteDirectory(new File(directory));
voiddeleteDirectory(String directory)
Deletes a directory.
File f = new File(directory);
deleteDirectory(f);