Skip to content

Instantly share code, notes, and snippets.

@perfectfoolish
Last active December 23, 2015 23:29
Show Gist options
  • Save perfectfoolish/6710499 to your computer and use it in GitHub Desktop.
Save perfectfoolish/6710499 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'rubyzip'
require 'find'
require 'zip/zip'
puts ""
puts "------------------File Search and Zip-----------------------------"
puts ""
print "Enter the search path : "
searchpath = gets
searchpath = searchpath.chomp
puts ""
print "Enter the search pattern : "
pattern = gets
pattern = pattern.chomp
puts"----------------------------------------------------------------------"
puts "Searching in " + searchpath + " for files matching pattern " + pattern
puts"----------------------------------------------------------------------"
puts ""
puts"----------------------------------------------------------------------"
puts "Zipping up the found files..."
puts"----------------------------------------------------------------------"
Zip::ZipFile.open("test.zip", Zip::ZipFile::CREATE) {
|zipfile|
Find.find(searchpath) do |path|
if FileTest.directory?(path)
if File.basename(path)[0] == ?.
Find.prune # Don't look any further into this directory.
else
next
end
else
if File.fnmatch(pattern,File.basename(path))
p File.basename(path)
zipfile.add(File.basename(path),path)
end
end
end
}
@perfectfoolish
Copy link
Author

have an error on line 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment