Java Utililty Methods Delete Folder

List of utility methods to do Delete Folder

Description

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

Method

voiddeleteFolder(File folder)
This method recursively deletes a folder.
File[] files = folder.listFiles();
for (File file : files) {
    if (file.isDirectory()) {
        deleteFolder(file);
    file.delete();
if (!folder.delete()) {
...
booleandeleteFolder(File folder)
delete Folder
boolean result = false;
try {
    String childs[] = folder.list();
    if (childs == null || childs.length <= 0) {
        if (folder.delete()) {
            result = true;
    } else {
...
voiddeleteFolder(File folder)
delete Folder
if (!folder.exists())
    throw new IOException("" + folder + " doesn't exist.");
if (!folder.isDirectory())
    throw new IOException("" + folder + " is not a folder.");
for (File fileOrFolder : folder.listFiles()) {
    if (fileOrFolder.isDirectory()) {
        deleteFolder(fileOrFolder);
        fileOrFolder.delete();
...
booleandeleteFolder(File folder)
delete Folder
if (folder.exists()) {
    if (folder.isDirectory()) {
        File[] subFiles = folder.listFiles();
        for (File subFile : subFiles) {
            if (subFile.isFile()) {
                deleteFile(subFile);
            } else {
                deleteFolder(subFile);
...
voiddeleteFolder(File folder)
Deletes a folder recursively.
for (File f : folder.listFiles()) {
    if (f.isDirectory()) {
        deleteFolder(f);
    } else {
        f.delete();
voiddeleteFolder(final File folder)
delete Folder
if (!folder.exists()) {
    return;
File[] files = folder.listFiles();
if (files != null) { 
    for (final File file : files) {
        deleteFolder(file);
if (!folder.delete()) {
    throw new IOException(String.format("Could not delete folder %s", folder));
booleandeleteFolder(final File folder)
Deletes a folder by individually deleting each file and subfolder folder.
boolean success = false;
if (folder.isDirectory()) {
    for (final File file : folder.listFiles()) {
        if (file.isDirectory()) {
            deleteFolder(file);
        } else {
            file.delete();
    success = folder.delete();
return success;
voiddeleteFolder(final String folder)
Delete folder.
File folderPath = new File(folder);
try {
    final File[] filesList = folderPath.listFiles();
    for (final File file : filesList) {
        file.delete();
    folderPath.delete();
} catch (Exception e) {
...
booleandeleteFolder(String folder)
Removes a directory and all sub-directories and files beneath it.
return deleteFolder(new File(folder));
booleandeleteFolder(String folder)
Deletes a folder from the file system.
File folder2Delete = new File(folder);
if (folder2Delete.exists()) {
    File[] files = folder2Delete.listFiles();
    for (int i = 0; i < files.length; i++) {
        if (files[i].isDirectory()) {
            deleteFolder(files[i].getPath());
        } else {
            files[i].delete();
...