Skip to content

Instantly share code, notes, and snippets.

@JGallardo
Created December 14, 2012 03:00
Show Gist options
  • Save JGallardo/4282322 to your computer and use it in GitHub Desktop.
Save JGallardo/4282322 to your computer and use it in GitHub Desktop.
Ruby script to compress files.
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