Java Utililty Methods Delete Tree

List of utility methods to do Delete Tree

Description

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

Method

voiddelTree(File f)
Delete directory tree.
delTree(f, true, null);
voiddelTree(File file)
del Tree
if (file.isFile()) {
    file.delete();
    return;
if (file.isDirectory()) {
    for (File f : file.listFiles())
        delTree(f);
file.delete();
booleandelTree(File file)
Delete either the supplied file or all files within the directory supplied or any sub-directories.
if (file.isFile()) {
    return file.delete();
File[] list = file.listFiles();
for (int i = 0; i < list.length; i++) {
    if (!delTree(list[i])) {
        return false;
return true;
voiddelTree(File file)
Recursively deletes all contents of the given directory.
if (!file.exists())
    return;
File[] fileList;
if ((fileList = file.listFiles()) != null) {
    for (File f : fileList) {
        if (f.isDirectory())
            delTree(f);
        else
...
booleandelTree(File file)
del Tree
if (file.isFile()) {
    return file.delete();
} else {
    String[] list = file.list();
    for (int i = 0; i < list.length; i++) {
        if (!delTree(new File(file, list[i]))) {
            return false;
return true;
voiddelTree(File file)
Delete a directory tree recursively.
File[] files = file.listFiles();
if (files != null) {
    for (int i = 0; i < files.length; i++) {
        if (files[i].isDirectory()) {
            delTree(files[i]);
files = file.listFiles();
if (files != null) {
    for (int i = 0; i < files.length; i++) {
        files[i].delete();
booleandelTree(File file)
Delete a directory recursively or delete a single file
if (file.exists()) {
    if (file.isDirectory()) {
        File[] files = file.listFiles();
        for (int i = 0; files != null && i < files.length; i++) {
            if (!delTree(files[i])) {
                return false;
    if (!file.delete()) {
        return false;
    } else {
        if (file.exists()) {
            return false;
    return true;
} else {
    return false;
voiddelTree(File root)
Delete an entire tree with files, subdirectories, etc.
if (!root.isDirectory())
    throw new IllegalArgumentException("Not a directory: " + root);
for (File f : root.listFiles()) {
    if (f.isDirectory())
        delTree(f);
    else
        f.delete();
root.delete();
voiddeltree(File root)
Purges the passed file.
if (root == null || !root.exists())
    return;
if (root.isDirectory()) {
    for (File subRoot : root.listFiles()) {
        if (subRoot.isFile()) {
            subRoot.delete();
        } else {
            deltree(subRoot);
...
voiddeltree(final String directory)
Delete a directory and its sub-files
deltree(new File(directory));