Posted By

studioevoque on 10/30/10


Tagged

java io directory


Versions (?)

Delete a directory


 / Published in: Java
 

A "quick and dirty" way to delete a directory. For more cleaner implementation, see http://www.google.com/codesearch/p?hl=en#SS2by_AKaLs/src/org/apache/commons/io/FileUtils.java&q=cleanDirectory&l=972

  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.  
  12. // The directory is now empty so delete it
  13. return dir.delete();
  14. }

Report this snippet  

You need to login to post a comment.