Posted By

karelklic on 02/27/08


Tagged

zip


Versions (?)

Lists all zip files containing any yaml file; also lists all invalid zip files and non-zip files in a directory tree


 / Published in: Groovy
 

  1. import java.util.zip.*
  2.  
  3. def processZip(file) {
  4. try {
  5. zf = new ZipFile(file.toString())
  6. for (entries = zf.entries(); entries.hasMoreElements();) {
  7. zipEntryName = entries.nextElement().getName()
  8. if (zipEntryName ==~ /.*yaml$/ || zipEntryName ==~ /.*yml$/)
  9. println file.toString() + ": " + zipEntryName
  10. }
  11. zf.close()
  12. println "ERROR: " + file.toString() + " is problematic zip!"
  13. }
  14. }
  15.  
  16. new File(".").eachFileRecurse() { f ->
  17. if (!f.isFile()) return
  18. if (f.toString() ==~ /.*zip$/) {
  19. processZip(f)
  20. }
  21. println "ERROR: " + f.toString() + " is not a zip file"
  22. }

Report this snippet  

You need to login to post a comment.