Last active
August 29, 2015 14:01
-
-
Save uilian/6eba5ef2fc369a565328 to your computer and use it in GitHub Desktop.
Find and extract file in zip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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