Java Snippet – Recursive Directory Deletion

Returns true on success, false on failure:
public static boolean deleteDir(File dir) {
if (dir.isDirectory()) {
String[] children = dir.list();
for (int i=0; i<children.length; i++) {
boolean success = deleteDir(new File(dir, children[i]));
if (!success) {
return false;
return dir.delete();

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top