Removing complete directory path from zip archive with ZipOutputStream

Jul 4, 2011 at 1:44 AM


I am currently using ZipOutputStream is zip up files, but when I do, it includes all of the root directoried in the zip file. I do I get it to not do this?

I saw a similar post about this, but the OP was using the AddFile method, which I am not. Is there any solution to this when using ZipOutputStream?



Jul 5, 2011 at 1:45 AM

ZipOutputStream.PutEntry() accepts a path, which is encoded into the zipfile.  To do what you want, change the path you pass to PutEntry().

You do not need to use the same path in PutEntry() that you use when calling File.Open() to read the file in the filesystem.

For example you could read a file via File.Open() at "c:\documents\July2011\Report1.xls" and put an entry in a zipfile called "\backup\Report.xls".