Java Utililty Methods File Path Delete

List of utility methods to do File Path Delete

Description

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

Method

voiddeleteDir(File directory, boolean removeAll)
delete Dir
if (directory == null || !directory.isDirectory()) {
    return;
for (File file : directory.listFiles()) {
    if (file.isDirectory() && removeAll) {
        deleteDir(file, removeAll);
    } else {
        file.delete();
...
booleandeleteDir(File dirFile)
delete Dir
if (!dirFile.exists()) {
    return false;
if (dirFile.isFile()) {
    return dirFile.delete();
} else {
    File[] files = dirFile.listFiles();
    if (files == null || files.length == 0) {
...
booleandeleteDir(File dirPath)
delete Dir
boolean isOk = true;
if (dirPath.isDirectory()) {
    try {
        deleteDirs(dirPath);
    } catch (Exception e) {
        isOk = false;
return isOk;
voiddeleteDir(File f)
delete Dir
File[] subs = f.listFiles();
for (int i = 0; i < subs.length; i++) {
    File sub = subs[i];
    if (sub.isDirectory()) {
        deleteDir(sub);
    } else {
        sub.delete();
f.delete();
booleandeleteDir(File f)
delete Dir
if (f.isDirectory()) {
    boolean res = true;
    for (File child : f.listFiles()) {
        res = deleteDir(child) && res;
    res = f.delete() && res;
    return res;
} else {
...
booleandeleteDir(File f)
delete Dir
if (f.isDirectory()) {
    String[] children = f.list();
    for (int i = 0; i < children.length; i++) {
        boolean success = deleteDir(new File(f, children[i]));
        if (!success) {
            System.err.println("warning: failed to delete file " + f);
            return false;
return f.delete();
booleandeleteDir(File fDir)
Deletes all files and sub directories under the specified directory including the specified directory
boolean bRetval = false;
if (fDir != null && fDir.exists()) {
    bRetval = deleteDirectoryContent(fDir);
    if (bRetval) {
        bRetval = bRetval && fDir.delete();
return bRetval;
...
voiddeleteDir(File file)
delete Dir
if (file.isDirectory()) {
    for (File child : file.listFiles()) {
        deleteDir(child);
file.delete();
booleandeleteDir(File path)
delete Dir
if (path == null || !path.isDirectory()) {
    return false;
File[] files = path.listFiles();
for (File file : files) {
    if (file.isDirectory()) {
        deleteDir(file);
    if (!file.delete()) {
        return false;
return path.delete();
voiddeleteDir(File path)
Recursively delete a directory and all the files it contains.
try {
    if (path.isDirectory()) {
        File[] files = path.listFiles();
        if (files != null) {
            for (int i = 0; i < files.length; i++) {
                deleteDir(files[i]);
    path.delete();
} catch (Exception e) {
    e.printStackTrace();