Android Utililty Methods Directory Remove Recursive

List of utility methods to do Directory Remove Recursive

Description

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

Method

voiddeltree(File directory)
deltree
if (directory.exists() && directory.isDirectory()) {
    File[] fileArray = directory.listFiles();
    for (int i = 0; i < fileArray.length; i++) {
        if (fileArray[i].isDirectory()) {
            deltree(fileArray[i]);
        } else {
            fileArray[i].delete();
    directory.delete();
voiddeltree(String directory)
deltree
deltree(new File(directory));
voidrecursiveRemoveDir(File directory)
This class del a directory recursively,that means delete all files and directorys.
if (!directory.exists())
    throw new IOException(directory.toString() + " do not exist!");
String[] filelist = directory.list();
File tmpFile = null;
for (int i = 0; i < filelist.length; i++) {
    tmpFile = new File(directory.getAbsolutePath(), filelist[i]);
    if (tmpFile.isDirectory()) {
        recursiveRemoveDir(tmpFile);
...
booleanremoveDirectories(File file)
recursively remove directory and all sub directories
if (!file.exists())
    return true;
if (file.isDirectory()) {
    File[] subFiles = file.listFiles();
    for (File subFile : subFiles) {
        if (!removeDirectories(subFile))
            return false;
return file.delete();
booleanremoveDirectories(File file, String regex)
recursively remove directory and all sub directories which matches regular expression
if (!file.exists())
    return true;
if (file.isDirectory()) {
    if (file.getName().matches(regex)) {
        if (!removeDirectories(file))
            return false;
    } else {
        File[] subFiles = file.listFiles();
...
Booleandelete(String root)
Delete File or Folder recursively
if (root == null) {
    return false;
File f = new File(root);
if (f.isDirectory()) {
    for (File tmp : f.listFiles()) {
        delete(tmp.getAbsolutePath());
return f.delete();
voidDeleteRecursive(File fileOrDirectory)
Elimina um ficheiro ou diretoria recursivamente.
if (fileOrDirectory.isDirectory())
    for (File child : fileOrDirectory.listFiles())
        DeleteRecursive(child);
try {
    fileOrDirectory.delete();
} catch (Exception e) {