Java Delete Directory deleteDirectory(File dir, boolean isInitialDelete)

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

Description

delete Directory

License

Open Source License

Declaration

public static boolean deleteDirectory(File dir, boolean isInitialDelete) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;

public class Main {

    public static boolean deleteDirectory(File dir, boolean isInitialDelete) {
        if (dir.isDirectory()) {
            if (dir.exists()) {
                for (File child : dir.listFiles()) {
                    try {
                        deleteDirectory(child, isInitialDelete);
                    } catch (Exception e) {
                        if (isInitialDelete)
                            continue;
                        else
                            return false;
                    }//  ww  w  . j  a v a  2  s .c o m
                }
            }
        }
        dir.delete();
        return true;
    }

    public static boolean isDirectory(File f) {
        if (f != null && f.exists() && f.isDirectory()) {
            return true;
        }
        return false;
    }
}

Related

  1. deleteDirectory(File dir)
  2. deleteDirectory(File dir)
  3. deleteDirectory(File dir)
  4. deleteDirectory(File dir)
  5. deleteDirectory(File dir, boolean isInitialDelete)
  6. deleteDirectory(File dir, boolean recursive)
  7. deleteDirectory(File dir, Map preserve)
  8. deleteDirectory(File directory)
  9. deleteDirectory(File directory)