|
Sunday, 08 January 2012 11:56 |
require 'zip/zip'
require 'zip/zipfilesystem'
include Zip
def compress(ppath)
ppath.sub!(%r[/$],'')
archive = File.join('./',File.basename(ppath))+'.zip'
FileUtils.rm archive, :force=>true
Zip::ZipFile.open(archive, 'w') do |zipfile|
Dir["#{ppath}/**/**"].reject{|f|f==archive}.each do |file|
zipfile.add(file.sub(ppath+'/',''),file)
end
end
end
# usage
temp = "./some_folder"
begin
compress(temp) # pack folder
FileUtils.remove_dir(temp,true) # remove non empty folder, which is packed
end
 Read more: |