Java File Path Delete deleteDirRecursive(String path)

Here you can find the source of deleteDirRecursive(String path)

Description

delete Dir Recursive

License

Apache License

Declaration

public static boolean deleteDirRecursive(String path) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.File;

public class Main {
    public static boolean deleteDirRecursive(String path) {
        return deleteDirRecursive(new File(path));
    }// w  ww.j  av  a2  s .c o  m

    public static boolean deleteDirRecursive(File dir) {
        if (dir.exists()) {

            if (!dir.isDirectory()) {
                throw new IllegalArgumentException("" + dir + " is not directory");
            }

            File[] files = dir.listFiles();
            for (int i = 0; i < files.length; i++) {
                if (files[i].isDirectory()) {
                    deleteDirRecursive(files[i]);
                } else {
                    files[i].delete();
                }
            }
        }
        return (dir.delete());
    }
}

Related

  1. deleteDirectoryInternal(File path)
  2. deleteDirectoryRecursively(File path)
  3. deleteDirectoryRecursivly(String path)
  4. deleteDirectoryTree(String directoryPath)
  5. deleteDirRecursive(String dirPath)
  6. deleteDirs(File path)
  7. deleteDirs(String pathname)
  8. deleteDirWithContent(final String path)
  9. deleteEmptDir(String Path, String username)