Java Recursive Delete recursiveRemoveDir(File dir)

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

Description

recursive Remove Dir

License

Open Source License

Declaration

public static void recursiveRemoveDir(File dir) 

Method Source Code

//package com.java2s;

import java.io.File;

public class Main {
    public static void recursiveRemoveDir(File dir) {
        // System.out.println("DEBUG: recursiveRemoveDir: " + dir.getPath());
        if (dir == null || !dir.exists()) {
            return;
        }/* www . ja  va 2s.co  m*/
        File[] files = dir.listFiles();
        for (int i = 0; i < files.length; i++) {
            if (files[i].isDirectory()) {
                recursiveRemoveDir(files[i]);
            } else {
                if (!files[i].delete()) {
                    System.out.println("ERROR: unable to delete file: " + files[i].getPath());
                }
            }
        }
        if (!dir.delete()) {
            System.out.println("ERROR: unable to delete directory: " + dir.getPath());
        }
    }
}

Related

  1. recursivelyDelete(final File root, final boolean deleteRoot)
  2. recursivelyDelete(String loc)
  3. recursivelyDeleteEmptyDirectories(File fileToDelete)
  4. recursivelyDeleteEmptyParentDirectoriesUpToRoot(String path, String root)
  5. recursivelyDeleteFile(File path)
  6. recursiveRemoveDir(File directory)