Last active
December 23, 2015 23:29
-
-
Save perfectfoolish/6710499 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
have an error on line 2