Android 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

voiddeleteContents(String directory)
delete all files (recursively) in a directory.
File f = new File(directory);
if (!f.exists()) {
    return;
if (!f.isDirectory()) {
    throw new IOException(directory + " is not a vaid directory");
for (String s : f.list()) {
...
voiddeleteDir(File pDirectory)
delete Dir
if (pDirectory.exists()) {
    if (pDirectory.isDirectory()) {
        for (File lFile : pDirectory.listFiles()) {
            if (!lFile.equals(pDirectory.getParentFile())) {
                deleteDir(lFile);
    pDirectory.delete();
booleandeleteDir(String path)
Deletes a file or directory.
return deleteDir(new File(path));
booleandeleteDirectory(File dir)
Deletes the directory and all of its subdirectories and files.
if (dir.isDirectory()) {
    String[] children = dir.list();
    for (int i = 0; i < children.length; i++) {
        boolean success = deleteDirectory(new File(dir, children[i]));
        if (!success) {
            return false;
return dir.delete();
voiddeleteDirectory(File dir)
delete Directory
if (!dir.exists())
    return;
File[] subs = dir.listFiles();
if (subs != null) {
    for (File f : dir.listFiles()) {
        if (f.isFile()) {
            if (!f.delete()) {
                throw new IllegalStateException(
...
voiddeleteDirectory(File directory)
delete Directory
if (!directory.exists()) {
    return;
cleanDirectory(directory);
if (!directory.delete()) {
    String message = "Directory " + directory
            + " unable to be deleted.";
    throw new IOException(message);
...
voiddeleteDirectory(File directory)
Deletes a directory recursively.
if (!directory.exists()) {
    return;
cleanDirectory(directory);
if (!directory.delete()) {
    String message = "Unable to delete directory " + directory
            + ".";
    throw new IOException(message);
...
booleandeleteDirectory(File path)
delete Directory
if (path.exists()) {
    File[] files = path.listFiles();
    for (int i = 0; i < files.length; i++) {
        if (files[i].isDirectory()) {
            deleteDirectory(files[i]);
        } else {
            files[i].delete();
return path.delete();
booleandeleteDirectory(File path)
delete Directory
if (path.exists()) {
    File[] files = path.listFiles();
    for (int i = 0; i < files.length; i++) {
        if (files[i].isDirectory()) {
            deleteDirectory(files[i]);
        } else {
            files[i].delete();
return (path.delete());
voiddeleteDirectory(File path)
Convenience function to delete a directory.
if (!path.exists())
    return;
for (File file : path.listFiles()) {
    if (file.isDirectory())
        deleteDirectory(file);
    else if (!file.delete()) {
        throw new IOException(String.format(
                "Unable to delete file '%s'", file));
...