Java Utililty Methods Folder Delete

List of utility methods to do Folder Delete

Description

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

Method

voidclearDir(File d)
clear Dir
File[] kids = d.listFiles();
if (kids != null) {
    for (File kid : kids) {
        if (kid.isDirectory()) {
            clearDir(kid);
        if (!kid.delete()) {
            throw new IOException(kid.getAbsolutePath());
...
booleanclearDir(File dir)
clear Dir
if (!dir.exists()) {
    return false;
for (File file : dir.listFiles()) {
    if (file.isDirectory()) {
        clearDir(file);
    if (!file.delete())
...
voidclearDir(File dir)
clear Dir
for (File f : dir.listFiles()) {
    if (f.isDirectory()) {
        clearDir(f);
    f.delete();
booleanclearDir(File dir)
Deletes all sub-files and sub-directories in the given directory.
if (!dir.isDirectory())
    return false;
File[] files = dir.listFiles();
if (files == null || files.length == 0)
    return true;
boolean cleared = true;
for (File sub : files) {
    cleared &= delete(sub);
...
booleanclearDir(File dir)
clear Dir
if (!dir.isDirectory())
    return false;
File[] files = dir.listFiles();
if (files == null || files.length == 0)
    return true;
boolean cleared = true;
for (File sub : files) {
    cleared &= delete(sub);
...
voidclearFiles(File dir)
Clears a directory of all its files.
File[] files = dir.listFiles();
for (int i = 0; i < files.length; i++)
    files[i].delete();
booleanclearFilesOnPath(String path)
clear Files On Path
File dir = new File(path);
if (!dir.exists()) {
    System.out.println(path + " does not exists");
    return false;
if (!dir.isDirectory()) {
    System.out.println(path + " is not directory");
    return false;
...
voidclearFolder(File f)
clear Folder
if (f.isDirectory()) {
    for (File c : f.listFiles())
        delete(c);
voidclearFolder(File[] children)
clear Folder
for (int i = 0; i < children.length; i++) {
    File[] second = children[i].listFiles();
    if (second != null && second.length > 0)
        clearFolder(second);
    children[i].delete();
voidclearFolder(String directoryLocation)
Deleet all the files from the specified location
File fDir = new File(directoryLocation);
File[] files = fDir.listFiles();
if (files != null) {
    for (File aFile : files) {
        aFile.delete();