Java File Path Delete deleteDirectory(String path)

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

Description

delete Directory

License

Open Source License

Declaration

public static int deleteDirectory(String path) 

Method Source Code


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

import java.io.File;

public class Main {
    public static int deleteDirectory(String path) {
        File dir = new File(path);
        if (!dir.exists() || !dir.isDirectory())
            return 4;
        if (deleteStuffRecursive(dir)) {
            return 0;
        }//from  ww  w  . ja v  a 2 s .c  om
        return 1;
    }

    private static boolean deleteStuffRecursive(File item) {
        if (item.exists()) {
            if (item.isDirectory()) {
                for (File child : item.listFiles()) {
                    if (!deleteStuffRecursive(child)) {
                        return false;
                    }
                }
            }
            return item.delete();
        }
        return false;
    }
}

Related

  1. deleteDirectory(String filePath)
  2. deleteDirectory(String path)
  3. deleteDirectory(String path)
  4. deleteDirectory(String path)
  5. deleteDirectory(String path)
  6. deleteDirectory(String path)
  7. deleteDirectory(String path)
  8. deleteDirectory(String sPath)
  9. deleteDirectoryAndContents(final File srcPath)