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

booleandeleteFolder(String name)
delete Folder
File file = new File(name);
if (file.isDirectory()) {
    deleteFiles(file);
return file.delete();
voiddeleteFolderContents(File folder)
delete Folder Contents
File[] files = folder.listFiles();
if (files != null)
    for (File f : files) {
        if (f.isDirectory()) {
            deleteFolderContents(f);
            f.delete();
        } else
            f.delete();
...
booleandeleteFolderContents(File folder)
delete Folder Contents
File[] files = folder.listFiles();
if (files != null) {
    for (File file : files) {
        if (file.isFile()) {
            if (!file.delete()) {
                return false;
        } else {
...
voiddeleteFolderContents(File folder)
delete Folder Contents
deleteFolderContents(folder, new ArrayList<String>());
voiddeleteFolderIfEmpty(File f)
delete Folder If Empty
if (f.listFiles().length == 0) {
    deleteFolder(f);
voiddeleteFolderRec(File dir)
Deletes recursively specified folder or file.
if (dir == null || !dir.exists() || !dir.isDirectory())
    return;
for (File file : dir.listFiles())
    if (file.isDirectory())
        deleteFolderRec(file);
    else if (!file.delete())
        file.deleteOnExit();
if (!dir.delete())
...
intdeleteFolderRecursive(File folder)
delete Folder Recursive
int count = 0;
if (folder == null)
    return count;
if (folder.exists()) {
    for (File f : folder.listFiles()) {
        if (f.isDirectory()) {
            count += deleteFolderRecursive(f);
            f.setWritable(true, false);
...
voiddeleteFolderRecursively(File file)
delete Folder Recursively
try {
    File[] allFiles = file.listFiles();
    if (allFiles == null) {
        file.delete();
        return;
    for (File f : allFiles) {
        if (f.isDirectory())
...
voiddeleteFolderRecursively(File folder)
delete Folder Recursively
if (folder != null && folder.isDirectory() && folder.canWrite()) {
    File[] listFiles = folder.listFiles();
    if (listFiles != null) {
        for (File f : listFiles) {
            if (f.isFile()) {
                f.delete();
            } else if (f.isDirectory()) {
                deleteFolderRecursively(f);
...