Posted By

hansamann on 01/03/07


Tagged

file directory deleting removing cascading


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

jsbournival
laurenceosx


Deleting all files and subdirectories


 / Published in: Groovy
 

This (almost) one-liner cascades into all subdirectories and deletes the files first, then the directories. Makes deleting a directory really easy. This was originally posted by John Wilson into the Groovy user list.

  1. def c
  2. c = {println "Dir ${it.canonicalPath}"; it.eachDir(c); it.eachFile{println "File ${it.canonicalPath}"; it.delete()}}
  3. c new File("test")

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: MarcDexet on January 3, 2007

@see Groovy Wiki.

Posted By: MarcDexet on January 3, 2007

@see Groovy Wiki.

Posted By: MarcDexet on January 3, 2007

Sorry I'm struggling with Markdown :)

You need to login to post a comment.