Possible bug - AddSelectedFiles -

Jun 9, 2009 at 4:46 PM

I've experienced the following issue. Looks like it may be a bug. The goal is to recursively walk a path and place all files in the root of the archive with no folders.

Files involved:


If I make the following call, I only end up with test1.txt and test2.txt in the root of the archive. Even though "recursive" is set to true it is not walking the tree. Notice that directoryPathInArchive is set to empty string so that all files in placed in root. If I make thecall without the directoryPathInArchive property the tree is walked as expected. It seems to be the combination of directoryPathInArchive="" and recursive=true that is causing the problem.

zip.AddSelectedFiles("*.*", filePathToZip, "", true);      // with filePathToZip being "C:\temp"

Is this a known issue or is my implementation incorrect?


Jun 12, 2009 at 1:12 AM
Edited Jun 12, 2009 at 1:28 AM

Hey Bob,

in fact, I think the behavior that you are seeing is correct. 

All the files are included in the resulting zip, but the directory structure on the disk is reproduced in the zip file, rooted in the zip file at "". 

This is not what you were expecting.  It sounds like you expected the directory structure to be flattened, but this is not what the method is expected to do.  In fact the expected behavior is to reproduce the dir hierarchy from the filesystem , in the zip file, but rooting it at the directory you specify in the zip file. 

I just checked this myself, and in fact you are correct - the files in the base directory (in your case c:\temp) are the only ones that appear in the root in the zip archive.  But, the rest of the files are in the zip archive, in a directory tree that reflects the filesystem.

I also checked the documentation, and in fact it does not state clearly that the filesystem hierarchy is NOT flattened.   I will update the doc to state it more clearly.


Jun 12, 2009 at 6:34 AM


Thanks for the quick reply. I don't believe I made the part about the files in the root very clear. In my tests (just ran them again) the only files I get AT ALL in the archive are the two in the root. The folder structure is gone entirely. Whether "recursive" is set to true or false I get the exact same result: test1.txt and test2.txt in the root of the archive and nothing else - no other files - no other folders.

Thanks again for any help you can provide.

- Bob

Jun 12, 2009 at 11:00 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Jun 12, 2009 at 11:05 AM


I created a workitem, http://dotnetzip.codeplex.com/WorkItem/View.aspx?WorkItemId=7883 

Attached to that work item is a test case.  Can you download it, compile it, and tell me the results you get? b

Jun 13, 2009 at 7:33 PM

Bob, Any update? did you get a chance to download and run that test case?

Jun 15, 2009 at 10:00 PM

Cheeso, ran the test case and posted a response to the work item.

Jun 16, 2009 at 12:53 AM
Edited Jun 16, 2009 at 12:57 AM

Ok, thanks.  That's baffling.  Can you post the zip file that gets produced by the test program?  And also the actual output of the program - the text it prints on the console. 
This is the output from my run:

clearing dir bobdir
creating dir bobdir
Creating file 'bobdir\Test1.txt' size(1856)
Creating file 'bobdir\Test2.txt' size(621)
Creating file 'bobdir\folder1\Test3.txt' size(1374)
Creating file 'bobdir\folder2\Test4.txt' size(1471)
Deleting file BobCheckItOut.zip
Creating zip file BobCheckItOut.zip
adding selection '*.*' from dir 'bobdir'...
found 4 files...
adding bobdir\Test1.txt...
adding bobdir\Test2.txt...
adding bobdir\folder1\Test3.txt...
adding bobdir\folder2\Test4.txt...

Checking file BobCheckItOut.zip
  Entry: Test1.txt
  Entry: Test2.txt
  Entry: /folder1/Test3.txt
  Entry: /folder2/Test4.txt