Java Utililty Methods Directory Delete

List of utility methods to do Directory Delete

Description

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

Method

booleanemptyDirectory(File dir)
Recursively deletes all the entries of a directory.
String[] children = dir.list();
boolean ok = true;
if (children != null) {
    for (int i = 0; i < children.length; ++i) {
        File child = new File(dir, children[i]);
        if (child.isDirectory()) {
            if (!removeFile(child,  true))
                ok = false;
...
voidemptyDirectory(File dir)
empty Directory
if (dir.exists() && dir.isDirectory()) {
    File[] tmpFiles = dir.listFiles();
    if (tmpFiles.length > 0) {
        for (File f : tmpFiles) {
            f.delete();
voidemptyDirectory(File directory)
Delete the content of a directory, but not the directory itself
File[] f = directory.listFiles();
if (f != null) {
    for (int i = 0; i < f.length; i++) {
        if (f[i].isDirectory()) {
            emptyDirectory(f[i]);
        f[i].delete();
booleanemptyDirectory(File directory)
empty Directory
boolean result = true;
File[] entries = directory.listFiles();
for (int i = 0; i < entries.length; i++) {
    if (!entries[i].delete()) {
        result = false;
return result;
...
booleanemptyDirectory(File path)
empty Directory
if (path.exists()) {
    File[] files = path.listFiles();
    for (int i = 0; i < files.length; i++) {
        if (files[i].isDirectory()) {
            deleteDirectory(files[i]);
        } else {
            if (!files[i].delete()) {
                return false;
...
voidemptyDirectory(final File directory)
empty Directory
for (final File file : directory.listFiles()) {
    if (file.isDirectory()) {
        emptyDirectory(file);
    if (!file.delete()) {
        throw new IOException("Can't delete " + file);