Sha256: c4ebd0c12e297a128d22736859b88f6f3a6b3fed01acdac909805664934fbd31

Contents?: true

Size: 1.44 KB

Versions: 38

Compression:

Stored size: 1.44 KB

Contents

#!/usr/bin/env ruby

$VERBOSE = true

$: << '../lib'

require 'zip'
require 'find'

module Zip
  module ZipFind
    def self.find(path, zipFilePattern = /\.zip$/i)
      Find.find(path) do |fileName|
        yield(fileName)
        next unless zipFilePattern.match(fileName) && File.file?(fileName)
        begin
          Zip::File.foreach(fileName) do |zipEntry|
            yield(fileName + File::SEPARATOR + zipEntry.to_s)
          end
        rescue Errno::EACCES => ex
          puts ex
        end
      end
    end

    def self.find_file(path, fileNamePattern, zipFilePattern = /\.zip$/i)
      find(path, zipFilePattern) do |fileName|
        yield(fileName) if fileNamePattern.match(fileName)
      end
    end
  end
end

if __FILE__ == $0
  module ZipFindConsoleRunner
    PATH_ARG_INDEX = 0
    FILENAME_PATTERN_ARG_INDEX = 1
    ZIPFILE_PATTERN_ARG_INDEX = 2

    def self.run(args)
      check_args(args)
      Zip::ZipFind.find_file(args[PATH_ARG_INDEX],
                             args[FILENAME_PATTERN_ARG_INDEX],
                             args[ZIPFILE_PATTERN_ARG_INDEX]) do |fileName|
        report_entry_found fileName
      end
    end

    def self.check_args(args)
      if (args.size != 3)
        usage
        exit
      end
    end

    def self.usage
      puts "Usage: #{$0} PATH ZIPFILENAME_PATTERN FILNAME_PATTERN"
    end

    def self.report_entry_found(fileName)
      puts fileName
    end
  end

  ZipFindConsoleRunner.run(ARGV)
end

Version data entries

38 entries across 32 versions & 5 rubygems

Version Path
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/rubyzip-1.2.1/samples/zipfind.rb
tdiary-5.0.11 vendor/bundle/gems/rubyzip-1.2.1/samples/zipfind.rb
vagrant-unbundled-2.1.2.0 vendor/bundle/ruby/2.3.0/gems/rubyzip-1.2.1/samples/zipfind.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/rubyzip-1.2.1/samples/zipfind.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/rubyzip-1.2.1/samples/zipfind.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/rubyzip-1.2.1/samples/zipfind.rb
tdiary-5.0.9 vendor/bundle/gems/rubyzip-1.2.1/samples/zipfind.rb
vagrant-unbundled-2.1.1.0 vendor/bundle/ruby/2.5.0/gems/rubyzip-1.2.1/samples/zipfind.rb
vagrant-unbundled-2.0.4.0 vendor/bundle/ruby/2.5.0/gems/rubyzip-1.2.1/samples/zipfind.rb
tdiary-5.0.8 vendor/bundle/ruby/2.5.0/gems/rubyzip-1.2.1/samples/zipfind.rb
tdiary-5.0.8 vendor/bundle/gems/rubyzip-1.2.1/samples/zipfind.rb
tdiary-5.0.8 vendor/bundle/gems/tdiary-5.0.7/vendor/bundle/gems/rubyzip-1.2.1/samples/zipfind.rb
vagrant-unbundled-2.0.3.0 vendor/bundle/ruby/2.5.0/gems/rubyzip-1.2.1/samples/zipfind.rb
vagrant-unbundled-2.0.2.0 vendor/bundle/ruby/2.5.0/gems/rubyzip-1.2.1/samples/zipfind.rb
vagrant-unbundled-2.0.2.0 vendor/bundle/ruby/2.4.0/gems/rubyzip-1.2.1/samples/zipfind.rb
tdiary-5.0.7 vendor/bundle/gems/rubyzip-1.2.1/samples/zipfind.rb
vagrant-unbundled-2.0.1.0 vendor/bundle/ruby/2.4.0/gems/rubyzip-1.2.1/samples/zipfind.rb
tdiary-5.0.6 vendor/bundle/gems/rubyzip-1.2.1/samples/zipfind.rb
vagrant-unbundled-2.0.0.1 vendor/bundle/ruby/2.4.0/gems/rubyzip-1.2.1/samples/zipfind.rb
vagrant-unbundled-1.9.8.1 vendor/bundle/ruby/2.4.0/gems/rubyzip-1.2.1/samples/zipfind.rb