Created
December 14, 2012 03:00
-
-
Save JGallardo/4282322 to your computer and use it in GitHub Desktop.
Ruby script to compress files.
This file contains 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 'zip/zip' | |
unless ARGV[0] | |
puts "Usage: ruby compress.rb <filename.ext>" | |
puts "Example: ruby compress.rb myfile.exe" | |
exit | |
end | |
file = ARGV[0].chomp | |
if File.exists?(file) | |
print "Enter zip filename:" | |
zip = "#{gets.chomp}.zip" | |
Zip::ZipFile.open(zip, true) do |zipfile| | |
begin | |
puts "#{file} is being added to the archive." | |
zipfile.add(file,file) | |
rescue Exception => e | |
puts "Error adding to zipfile: \n #{e}" | |
end | |
end | |
else | |
puts "\nFile could not be found." | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment