Directories in Zip wont work

Feb 23, 2010 at 7:57 AM
Edited Feb 23, 2010 at 7:58 AM

Hi there,

i downloaded DotNetZip Library (which is great to use by the way). For some reason thou i just cant get any Directories into the Zip file.When i try to add a existing directory, just the files in the subfolders are copied into the zip. I used


zip.AddDirectory(@"SomeFolder\Folder", "TestFolder");

zip.AddFile("SomeFile", "Folder1");

I tried out with release 1.7, 1.8 and 1.9 as development Environment i use Visual Studio 2005 Team Edition with .NET Version 2.0.50727


I hope someone knows a solution, for i like to use that Library.


Feb 23, 2010 at 12:05 PM

What do you expect to happen?  Can you give me a specific, concrete example?



Feb 24, 2010 at 7:52 AM

I expected to have subfoldes in the Zip file. If i want to zip a folder like this:


All the files get zipped, like this:\

Want i expected, is to get a Zip file like this:\

Hope this somehow makes sense :)

Feb 24, 2010 at 8:32 PM

You're saying that when zipping a folder, the directory hierarchy in the filesystem gets flattened in the zip file. I don't think this is true.

Please provide code that reproduces this condition.

I just tried it this way:

c:\temp>dir /s Folder1
 Volume in drive C has no label.
 Volume Serial Number is C8BC-2EBD

 Directory of c:\temp\Folder1

02/24/2010  04:24 PM              .
02/24/2010  04:24 PM              ..
01/03/2005  08:43 PM            19,757 CRijndael.cls
10/04/2009  03:00 PM            75,069 Output.log
02/24/2010  04:24 PM              subfolder
               2 File(s)         94,826 bytes

 Directory of c:\temp\Folder1\subfolder

02/24/2010  04:24 PM              .
02/24/2010  04:24 PM              ..
12/19/2008  12:27 PM             4,962 perl-v.txt
               1 File(s)          4,962 bytes

     Total Files Listed:
               3 File(s)         99,788 bytes
               5 Dir(s)   6,039,547,904 bytes free

c:\temp>zipit -r+ -d Folder1 Folder1
adding selection '*.*' from dir 'Folder1'...
found 3 files...
adding Folder1\CRijndael.cls...
adding Folder1\Output.log...
adding Folder1\subfolder\perl-v.txt...

c:\temp>unzip -l

Modified                     Size  Ratio       Packed  pw?      CRC Filename
2005-01-03 20:43:54         19757    81%         3768    N 59BB7A98 Folder1/CRijndael.cls
2009-10-04 16:00:52         75069    94%         4692    N EDE5A53F Folder1/Output.log
2008-12-19 12:27:16          4962    51%         2428    N E02CDCB1 Folder1/subfolder/perl-v.txt
                            99788                                   3 files

The zipit.exe and unzip.exe tools are from the DotNetZip tools v1.9 download. Zipit.exe uses ZipFile.AddSelectedFiles() to create a zip file. Unzip.exe uses a foreach loop to enumerate the files in the zip. As you can see there's a directory hierarchy with files at several levels in the filesystem. When I create the zip file, that directory hierarchy is reproduced in the zipfile.

Maybe, instead of no directory hierarchy at all, you are noticing that the toplevel directory form the filesystem is not present in the zip file, though the subdirectories are. This is as documented and expected. If you want the files to all appear in a toplevel ("root") directory in the archive, then specify a directoryInArchive param to AddSelectedFiles(). The -d argument to zipit.exe does this.

Feb 25, 2010 at 10:41 AM

.... ok i'm an idiot... .winzip just displayed it diffent and i wasn't used to that. Sry for bothering

Feb 25, 2010 at 8:43 PM

no bother, I spent only a moment on it.