/** * Completely obliterates the given file, leaving no trace of it. * * @param file */ public static void obliterate(File file) { if (file.isFile()) { file.delete(); file.deleteOnExit(); } else if (file.isDirectory()) { // delete everything inside, then delete this on exit for (File child : file.listFiles()) { obliterate(child); } file.delete(); file.deleteOnExit(); } }
/** * Guts the given folder. All files inside it are deleted. The given folder is not deleted. * * @param file a folder */ public static void purgeFolder(File folder) { // delete everything inside this for (File file : folder.listFiles()) { obliterate(file); } }