Android Directory Delete deleteDirectory(File dir)

Here you can find the source of deleteDirectory(File dir)

Description

Deletes the directory and all of its subdirectories and files.

Parameter

Parameter Description
dir a parameter

Return

True if directory is successfully deleted.

Declaration

public static boolean deleteDirectory(File dir) 

Method Source Code

//package com.java2s;

import java.io.File;

public class Main {
    /**/*w  w  w .  j ava 2 s.c  o m*/
     * Deletes the directory and all of its subdirectories and files.
     * @param dir
     * @return True if directory is successfully deleted.
     */
    public static boolean deleteDirectory(File dir) {
        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;
                }
            }
        }

        // The directory is now empty so delete it
        return dir.delete();
    }
}

Related

  1. deleteContents(String directory)
  2. deleteDir(File pDirectory)
  3. deleteDir(String path)
  4. deleteDirectory(File dir)
  5. deleteDirectory(File directory)
  6. deleteDirectory(File directory)
  7. deleteDirectory(File path)