Skip to content

Instantly share code, notes, and snippets.

@uilian
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uilian/6eba5ef2fc369a565328 to your computer and use it in GitHub Desktop.
Save uilian/6eba5ef2fc369a565328 to your computer and use it in GitHub Desktop.
Find and extract file in zip
import groovy.io.FileType
String targetFileName = 'someFileName'
String filter = 'someFilter'
def dir = new File(".")
dir.eachFileRecurse(FileType.FILES){ file ->
if (file.name.endsWith(filter)) {
def zipFile = new java.util.zip.ZipFile(file)
zipFile.entries().each{ entry ->
if(entry.name.indexOf(targetFileName) > 0){
def out = new BufferedOutputStream(new FileOutputStream(entry.name))
out << zipFile.getInputStream(entry)
out.close()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment