Deleting all files and subdirectories


/ Published in: Groovy
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  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

You need to login to post a comment.