Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

This script searches one or more jar or zip files for a specified file/directory.

Code Block
import java.util.jar.*

 * Searches entries (file name and directory, if any) in one or more named
 * compressed (jar/zip) files, or in all compressed files in a named directory.
 * To specify a search that includes special characters, like a period, use
 * a backslash: \.xml
    if( args.size() < 2){
        println "Required parameters: searchString filePath [filePath]\n"
        println "NOTE: filePath may be a directory, which will search all jar/zip"
	println "      files in all subdirectories"
    def searchstr = args[0]
    args[1..-1].each{searchInputFile(searchstr, new File(it))}

    def searchInputFile(text, inputFile){
        def filePattern = ~/.*\.(jar|zip)$/
                if(!it.isDirectory() && it.getName() =~ filePattern)
                    searchCompressedFile(text, it)
            if(inputFile.getName() =~ filePattern){
                searchCompressedFile(text, inputFile)

    def searchCompressedFile(text, file){
            new JarFile(file).entries().each{ entry ->
                if ( =~ text){
                    println "\n$ : $file.canonicalPath"
        }catch(Throwable t){
            println "\nFailed to open $file.canonicalPath: ${t.toString()}"