Java tutorial
//package com.java2s; import java.io.File; public class Main { public static boolean delDir(String dirPath, boolean delFile) { if (delFile) { File file = new File(dirPath); if (file.isFile()) { return file.delete(); } else if (file.isDirectory()) { if (file.listFiles().length == 0) { return file.delete(); } else { int zfiles = file.listFiles().length; File[] delfile = file.listFiles(); for (int i = 0; i < zfiles; i++) { if (delfile[i].isDirectory()) { delDir(delfile[i].getAbsolutePath(), true); } delfile[i].delete(); } return file.delete(); } } else { return false; } } else { return new File(dirPath).delete(); } } }