DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
How To ZIP Complete Folder Without Path And With Name Of A Folder
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





