Java Delete Directory deleteDirectory(String dirName)

Here you can find the source of deleteDirectory(String dirName)

Description

delete Directory

License

Open Source License

Declaration

public static boolean deleteDirectory(String dirName) 

Method Source Code


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

import java.io.*;

public class Main {

    public static boolean deleteDirectory(String dirName) {
        return deleteDirectory(new File(dirName));
    }//from   w  w w. j a v a  2s.  c  o  m

    public static boolean deleteDirectory(File dir) {
        if ((dir == null) || !dir.isDirectory()) {
            throw new IllegalArgumentException("Argument " + dir + " is not a directory. ");
        }

        File[] entries = dir.listFiles();
        int sz = entries != null ? entries.length : 0;

        for (File entry : entries != null ? entries : new File[0]) {
            if (entry.isDirectory()) {
                if (!deleteDirectory(entry)) {
                    return false;
                }
            } else {
                if (!entry.delete()) {
                    return false;
                }
            }
        }

        return dir.delete();
    }
}

Related

  1. deleteDirectory(String dir)
  2. deleteDirectory(String directory)
  3. deleteDirectory(String directory)
  4. deleteDirectory(String directoryName)
  5. deleteDirectory(String directoryName)
  6. deleteDirectory(String dirName)
  7. deleteDirectory(String dirname, boolean recursive)
  8. deleteDirectory(String fileName)
  9. deleteDirectory(String folder)