Java Snippet – Recursive Directory Deletion

Returns true on success, false on failure:

JAVA:
  1. public static boolean deleteDir(File dir) {
  2.     if (dir.isDirectory()) {
  3.         String[] children = dir.list();
  4.         for (int i=0; i<children.length; i++) {
  5.             boolean success = deleteDir(new File(dir, children[i]));
  6.             if (!success) {
  7.                 return false;
  8.             }
  9.         }
  10.     }
  11.     return dir.delete();
  12. }

No Comments so far
Leave a comment



Leave a comment
Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

(required)

(required, but not displayed publically)