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

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(String directory)
delete Directory
deleteDirectory(new File(directory));
booleandeleteDirectory(String path)
delete Directory
return deleteDirectory(new File(path));
booleandeleteDirectory(String path)
delete Directory
return deleteDirectory(new File(path));
voiddeleteDirectory(final File directory)
Deletes a directory recursively.
if (!directory.exists()) {
    return;
if (!isSymbolicLink(directory.toPath())) {
    cleanDirectory(directory);
if (!directory.delete()) {
    final String message = "Unable to delete directory "
...
voiddeleteFiles(String directory)
Deletes all files located in this directory.
File dir = new File(directory);
String[] list = dir.list();
if (list.length > 0) {
    for (int i = 0; i < list.length; i++) {
        File file = new File(directory, list[i]);
        file.delete();
voiddeleteFiles(String directory, String dontDelete)
Deletes all files in the given directory with the exception of the given file name identified in dontDelete.
File dir = new File(directory);
String[] list = dir.list();
if (list.length > 0) {
    for (int i = 0; i < list.length; i++) {
        File file = new File(directory, list[i]);
        if (!file.getPath().equalsIgnoreCase(dontDelete)) {
            file.delete();
voiddeleteFiles(String directory, String[] dontDelete)
Deletes all files in this directory with the exception of the file names given in the dontDelete array.
File dir = new File(directory);
String[] list = dir.list();
if (dontDelete == null) {
    deleteFiles(directory);
} else if (dontDelete.length == 1 && dontDelete[0] != null) {
    deleteFiles(directory, dontDelete[0]);
} else if (list.length > 0) {
    for (int i = 0; i < list.length; i++) {
...
voiddeleteSubdirs(String directory)
Deletes all subdirectories of the given directory.
File parentDir = new File(directory);
String[] list = parentDir.list();
File subDir;
if (list.length == 0) {
    return;
for (int i = 0; i < list.length; i++) {
    subDir = new File(directory, list[i]);
...
booleanremoverDiretorio(File dir)
remover Diretorio
if (dir.isDirectory()) {
    String[] children = dir.list();
    for (int i = 0; i < children.length; i++) {
        boolean success = removerDiretorio(new File(dir,
                children[i]));
        if (!success) {
            return false;
return dir.delete();