Java File Path Delete deleteDir(File dirPath)

Here you can find the source of deleteDir(File dirPath)

Description

delete Dir

License

Open Source License

Declaration

public static boolean deleteDir(File dirPath) 

Method Source Code


//package com.java2s;
import java.io.File;

public class Main {

    public static boolean deleteDir(File dirPath) {
        boolean isOk = true;
        if (dirPath.isDirectory()) {
            try {
                deleteDirs(dirPath);//from  ww w  .j a v  a2  s . c  o m
            } catch (Exception e) {
                isOk = false;
            }
        }
        return isOk;
    }

    public static boolean deleteDir(String path) {
        return deleteDir(new File(path));
    }

    private static void deleteDirs(File path) {
        File[] files = null;
        if (path.isDirectory()) {
            path.delete();
            files = path.listFiles();
            if (files != null) {
                for (int i = 0; i < files.length; i++) {
                    deleteDirs(files[i]);
                }
            }
        }
        path.delete();
    }
}

Related

  1. deleteDir(File directory)
  2. deleteDir(File directory)
  3. deleteDir(File directory)
  4. deleteDir(File directory, boolean removeAll)
  5. deleteDir(File dirFile)
  6. deleteDir(File f)
  7. deleteDir(File f)
  8. deleteDir(File f)
  9. deleteDir(File fDir)