Subdirectories in Zip file using ZipOutputStream
Asked Answered
H

1

5

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.

Hyalite answered 6/12, 2011 at 2:33 Comment(0)
H
7

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'.

Hyalite answered 6/12, 2011 at 7:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.