Compressing Zip with directory entries intact

+1 vote
asked Dec 30, 2013 by Chris6 (280 points)
edited Feb 27, 2014

RebexZip does not add directory entries to the zip archive, is there a way I can force these to be added?

Rebexzip zip entries (2):

root.txt
a/file in directory a.txt

Winzip / Winrar zip entries (3):

root.txt
a/
a/file in directory a.txt

In this case "a/" is missing from rebex archive, causing a 3rd parties unzip function to fail. (they use java)

Code I am using to read the zip entries: http://www.roseindia.net/tutorial/java/corejava/zip/ShowEntries.html

This code also doesnt show directory: http://www.java-examples.com/determine-if-zip-entry-directory-example

==== Additional details to replicate

        using (ZipArchive zip = new ZipArchive(@"E:\\rebex3.zip"))
        {
            // This line is not calling 'CreateDirectory' internally for directories
            zip.Add(@"E:\z\*", @"\", Rebex.IO.TraversalMode.Recursive);

            // Manually adding directory & adding a file add the correct entries
            zip.CreateDirectory(@"\test");
            zip.AddFile(@"E:\temp\x.pdf", @"\test\x.pdf");
        }

produces the following entries output (note missing "a/")

root.txt
a/file in directory a.txt
test/
test/x.pdf

===========

Will you fix this or should I simply write my own method for adding directories to a zip archive recursively?

Applies to: Rebex ZIP
commented Dec 31, 2013 by Jan Sotola (17,670 points)
edited Dec 31, 2013

I need to consult it with developer who is on vacation now. We'll try to answer you later.

commented Dec 31, 2013 by Chris6 (280 points)
edited Dec 31, 2013

I have worked around the problem by creating the folders manually, so this could be moved to wish list.

thank you, have a great 2014.

2 Answers

0 votes
answered Jan 7, 2014 by Pavel Matyska (15,060 points)
edited Feb 27, 2014

Rebex ZIP 2014 R1 adds ZipArchiveOptions.CreateDirectoryEntries option that causes directory entries to always be created.

To workaround the issue you reported, please enable the newly added option like this:

zip.Options.CreateDirectoryEntries = true;
commented Jan 19, 2014 by Chris6 (280 points)
edited Feb 10, 2014

Do you have a release schedule I can work towards or could you provide a pre-release version (I am a licensed user) thanks.

commented Jan 20, 2014 by Pavel Matyska (15,060 points)
edited Feb 10, 2014

Hi Chris, please send us your pre-release request on support@rebex.net from your registered emial and we will make one for you.

commented Feb 27, 2014 by Lukas Pokorny (126,910 points)
edited Feb 27, 2014

Rebex ZIP 2014 R1 has just been released and includes this option.

0 votes
answered Feb 10, 2014 by Chris6 (280 points)
edited Feb 11, 2014

Sorry it's taken a while to get back to you, I have tried the hot fix you sent me with the following directory structure:

E:>tree /F E:\z Folder PATH listing Volume serial number is 0839-D1FE E:\Z │ file in root.txt │ └───a │ file in folder a.txt │ └───b file in folder b.txt E:>

When I create a zip using the hotfix I get the following entries:

List of contents in zip file file in root.txt a/file in folder a.txt a/b/file in folder b.txt

When I create a zip via windows or winrar I get the following

List of contents in zip file z/ z/a/ z/a/b/ z/a/b/file in folder b.txt z/a/file in folder a.txt z/file in root.txt

I am using the following code and the HotfixBuild5135:

        using (ZipArchive zip = new ZipArchive(@"E:\\rebex3.zip"))
        {
            zip.Add(@"E:\z\*", @"\", Rebex.IO.TraversalMode.Recursive);
        }

Do I need to make any code changes, I am 100% sure I am using the correct DLL as I made a blank project.

commented Feb 10, 2014 by Lukas Pokorny (126,910 points)
edited Feb 10, 2014

Please try enabling the new option by adding zip.Options.CreateDirectoryEntries = true; to your code. It is false by default.

commented Feb 10, 2014 by Chris6 (280 points)
edited Feb 11, 2014

Thanks, I can confirm it works now.

List of contents in zip file
file in root.txt
a/
a/file in folder a.txt
a/b/
a/b/file in folder b.txt
...