Question

I am creating a zip file using the technique described here:

http://info.michael-simons.eu/2008/01/21/using-rubyzip-to-create-zip-files-on-the-fly/

The client has asked that I include subdirectories in this zip file. I have searched the ZipOutputStream documentation but I see no way to include directories. Is there a way I can do this with ZipOutputStream? Should I be using a different class than ZipOutputStream?

Also, the files that I am zipping are not on the local filesystem, but are stored in a cloud service.

Was it helpful?

Solution

Figured out the answer, thought I would put it here for search engines to find.

Anyway, the link I posted used

zos.put_next_entry("some-funny-name.jpg")

to add files to the zip file. Turns out, that string parameter isn't just a filename, it can be a path as well! So using

zos.put_next_entry("some-random-folder/some-funny-name.jpg")

Will make your zip file contain a folder called 'some-random-folder', with a file called 'some-funny-name.jpg'.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top