This project is read-only.

AddDirectory : Logic difference between DotNet Zip an others archivers

Oct 10, 2008 at 10:02 AM

I noticed something quite strange (or at least different) with DotNet Zip.

When you compress a directory with WinRAR and 7zip (right click on a folder under Windows) :
=> The ouput archives contains in the root the folder.

When you compress a directory with DotNet Zip (using the WinForms sample) :
=> The output archive contains the content of the folder in the root

Cheeso, may be we need an option in the AddDirectory method to either compress the folder content or compress with the folder in root.

Oct 10, 2008 at 5:26 PM
Can you be more specific about what you see?
with an example of how the files are structured and how you would like the files to be structured.
Oct 13, 2008 at 10:31 AM
Ok let's take the following example :

I would like to compress the followinf folder tree :
- Temp
    - subfolder
        - file2.txt

With all archivers (WinRAR, 7zip, ...), the result archive ( contains :
- Temp
    - subfolder
        - file2.txt
    - file1.txt

With DotNet Zip, the result archive ( contains :
- subfolder
    - file2.txt
- file1.txt

That should be clear enough now :)

Oct 13, 2008 at 10:20 PM

Can you try:

      using (var zip = new ZipFile())
	zip.AddDirectory(directory, System.IO.Path.GetFileName(directory));

This will give you the dir structure you want I think.

I faced this challenge in creating the interface. What if someone wanted to create a directory that contained a bunch of files, then zip up that directory, but the resulting structure of the entries within the zip should NOT have the toplevel containing directory? In other words it was the opposite of the situation you wanted. And in the interface, there was no way to do that. So I modified the default behavior of ZipFile.AddDirectory() to NOT include the toplevel directory. You can still get the old behavior if you want it, by specifying a directory name explicitly, as in my code snippet above. I felt that was a good tradeoff.

I hope this works for you.

Oct 13, 2008 at 10:31 PM
ps: this behavior of AddDirectory(string) is documented in the v1.6 CHM file:

        /// Top-level entries in the named directory will appear as top-level
        /// entries in the zip archive.  Entries in subdirectories in the named
        /// directory will result in entries in subdirectories in the zip archive.

I just modified the doc to address your situation, and provide explicit instructions for how to get the containing directory.
Oct 13, 2008 at 10:45 PM
Awesome !

Thanks for the support Cheeso.