Java File Path Delete deleteDirRecursive(String dirPath)

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

Description

delete Dir Recursive

License

Open Source License

Declaration

public static boolean deleteDirRecursive(String dirPath) 

Method Source Code


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

import java.io.File;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class Main {
    public static boolean deleteDirRecursive(String dirPath) {
        File dir = new File(dirPath);
        if (dir.isDirectory()) {
            File[] children = dir.listFiles();
            for (int i = 0; i < children.length; i++) {
                boolean success = deleteDirRecursive(children[i].getAbsolutePath());
                if (!success) {
                    return false;
                }/*w  ww .j a v a2  s  . c  o m*/
            }
        }
        return dir.delete();
    }

    public static Collection<File> listFiles(String rootDor) {
        File root = new File(rootDor);
        List<File> files = new ArrayList<File>();
        listFiles(files, root);
        return files;
    }

    private static void listFiles(List<File> files, File dir) {
        File[] listFiles = dir.listFiles();
        for (File f : listFiles) {
            if (f.isFile()) {
                files.add(f);
            } else if (f.isDirectory()) {
                listFiles(files, f);
            }
        }
    }
}

Related

  1. deleteDirectoryIncludeContent(String folderPath)
  2. deleteDirectoryInternal(File path)
  3. deleteDirectoryRecursively(File path)
  4. deleteDirectoryRecursivly(String path)
  5. deleteDirectoryTree(String directoryPath)
  6. deleteDirRecursive(String path)
  7. deleteDirs(File path)
  8. deleteDirs(String pathname)
  9. deleteDirWithContent(final String path)