This commit is contained in:
yanxd 2014-04-15 16:06:32 +08:00
parent 399d7b559a
commit 4da8b4e5f6
1 changed files with 3 additions and 2 deletions

View File

@ -26,10 +26,11 @@ class TestController < ApplicationController
folder = "#{Rails.root}/files" folder = "#{Rails.root}/files"
input_filename = files_path input_filename = files_path
zipfile_name = "#{Rails.root}/tmp/archiveZip/archive_#{Time.now.to_i}.zip" zipfile_name = "#{Rails.root}/tmp/archiveZip/archive_#{Time.now.to_i}.zip"
Rails.logger.info "================================================================================================================================================================================================================================================================================================================================================================================================#{zipfile_name}"
Dir.mkdir(File.dirname(zipfile_name)) if File.exist?(File.dirname(zipfile_name))
Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile| Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
input_filename.each do |filename| input_filename.each do |filename|
zipfile.add(filename.split('/').last, folder + '/' + filename) zipfile.add(File.basename(filename), folder + '/' + filename)
end end
zipfile.get_output_stream("ReadMe"){ |os| zipfile.get_output_stream("ReadMe"){ |os|
os.write "Homeworks" os.write "Homeworks"