Wednesday, July 18, 2012

[Rails] Zipping files contained in a dir (rubyzip)

hey so I'm trying to zip all the files contained in a directory
(RubyZip). heres what I have:



def bundle
#create the ZIPfile with the title of (:id).zip
bundle_filename = "public/attachments/#{self.id}/#{self.id}.zip"

#open the ZIPfile in order to add items in
Zip::ZipFile.open(bundle_filename, Zip::ZipFile::CREATE) {
|zipfile|
Dir.foreach("public/attachments/#{self.id}") do |item|
t = File.open(item)
zipfile.add(t, "public/attachments/#{self.id}")
end
}

#change permissions on ZIPfile
File.chmod(0644, bundle_filename)
self.save
end

This successfully executes the first line and creates the zip file with
the correct name but it is not adding to the zip file all the files
contained in that directory. Any Ideas?

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate