Sha256: 373e71e2594f8fee1b42de93c794eedb1ef5e1374af428912b60d0ef3ef0e82c

Contents?: true

Size: 1.36 KB

Versions: 37

Compression:

Stored size: 1.36 KB

Contents

#!/usr/bin/env ruby

$VERBOSE = true

$: << "../lib"

require 'zip/zip'
require 'find'

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

    def self.find_file(path, fileNamePattern, zipFilePattern = /\.zip$/i)
      self.find(path, zipFilePattern) {
	|fileName|
	yield(fileName) if fileNamePattern.match(fileName)
      }
    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]) {
	|fileName|
	report_entry_found fileName
      }
    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

37 entries across 37 versions & 15 rubygems

Version Path
IronDigital-rubyzip-0.9.2 samples/zipfind.rb
agraham-rubyzip-0.9.1 samples/zipfind.rb
erawk-rubyzip-0.9.1 samples/zipfind.rb
erawk-rubyzip-0.9.2 samples/zipfind.rb
expectedbehavior-rubyzip-0.9.1.2 samples/zipfind.rb
febeling-rubyzip-0.9.2 samples/zipfind.rb
mksm-rubyzip-0.9.3 samples/zipfind.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/rubyzip-0.9.9/samples/zipfind.rb
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/rubyzip-0.9.8/samples/zipfind.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/rubyzip-0.9.8/samples/zipfind.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/rubyzip-0.9.8/samples/zipfind.rb
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/rubyzip-0.9.8/samples/zipfind.rb
rubyzip-0.9.9 samples/zipfind.rb
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/rubyzip-0.9.8/samples/zipfind.rb
rubyzip-0.9.8 samples/zipfind.rb
rubyzip-0.9.7 samples/zipfind.rb
frameworks-capybara-0.2.0.rc6 vendor/bundle/ruby/1.8/gems/rubyzip-0.9.6.1/samples/zipfind.rb
frameworks-capybara-0.2.0.rc5 vendor/bundle/ruby/1.8/gems/rubyzip-0.9.6.1/samples/zipfind.rb
frameworks-capybara-0.2.0.rc4 vendor/bundle/ruby/1.8/gems/rubyzip-0.9.6.1/samples/zipfind.rb
frameworks-capybara-0.2.0.rc3 vendor/bundle/ruby/1.8/gems/rubyzip-0.9.6.1/samples/zipfind.rb