How to add disk in zip using DotNetZip

This forum is the place to discuss issues related to ReportPro, Xs2Ado, Vo2Ado, bBrowser and other 3rd party products
Post Reply
ic2
Posts: 1813
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

How to add disk in zip using DotNetZip

Post by ic2 »

This is probably something Fabrice can answer? (as FabZip is based on DotNetZip).

I use DotNetZip for creating zips. It has many option but I couldn't find if it is possible to store the disk where the file is located, in the archive. E.g. like the Absolute mode in 7-Zip. As far as I can see I can only do this:

Code: Select all

zip.AddFile(cFileFull, cPath);
When cFileFull is e.g. "c:tempSomeFile.txt" and cPath = "c:temp" opening the zipfile shows

temp

while I would like to see

C
and then, when I click on C

temp

This would allow storing the same path/file found on different drives. Is this possible?

Dick
User avatar
Fabrice
Posts: 420
Joined: Thu Oct 08, 2015 7:47 am
Location: France

How to add disk in zip using DotNetZip

Post by Fabrice »

Hi Dick,
If I get you right, your goal is to store the "original" disk (and path may be) in the Zip File ?
I would think that this is not possible per design : You always store relative's path of file.
And I think this is good : Imagine zipping a file stored originally on a Y: drive, trying to unzip it... when you don't have a Y drive ?

That said, You (as a developer) can inject some informations within the ZipFile (the container), or per file inside the Zip, in order to keep that info :
The ZipFile and the ZipEntry classes have a property named Comment. You can store here any information you would find usefull in String format, so... It's up to you ;)

HTH,
Fab
XSharp Development Team
fabrice(at)xsharp.eu
User avatar
wriedmann
Posts: 3668
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

How to add disk in zip using DotNetZip

Post by wriedmann »

Hi Dick,
the zip file format does not defines drives, it allows only to store the drive label.
On other platforms than Windows (and DOS) there is no drive, only folders.
So this is not a problem of DotNetZip, but of the zip format.
And as Fabrice wrote: it would be very risky to restore to the same drive letter: immagine you are saving from a USB drive on one machine and the restore would overwrite a network drive or a local disk on a different machine.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
ic2
Posts: 1813
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

How to add disk in zip using DotNetZip

Post by ic2 »

Hello Wolfgang, Fabrice,

Thanks for your replies. I think it is a 7-Zip feature, see picture. I select Absolute pathnames and when opening the zip in Explorer it is empty but in 7-Zip you see first the disk and then the directory.

I think this is better, because now selecting a file with the same name on c:temp and d:temp means the latter won't be added in the zip. And you can restore in a different disk. But I also think it would be hard to achieve as it is not standard supported in DotNetZip.
7zipincludingdisk.jpg
7zipincludingdisk.jpg (44.69 KiB) Viewed 349 times
EDIT: I actually didn't try what would happen if I add the same file(name) residing in the same directory for 2 different disks.

Turns out that both files are added, with the same name in the same directory. Open each of the files and you see the different content. So I think it's indeed a good idea to check out the comment option, to at least show from which disk the files were.


Dick
ic2
Posts: 1813
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

How to add disk in zip using DotNetZip

Post by ic2 »

Hello Fabrice,

Your reply about using the comment turned out to be an absolutely brilliant workaround. Instead of zip.AddFile(cFileFull, cPath); the code is now:

Code: Select all

var zipEntry=zip.AddFile(cFileFull, cPath);
zipEntry.Comment=cPath.Substring(0,1);
In a program like 7-zip you can see the comment, being the drive letter, and this is then the only difference if I add 2 exactly the same files in the same directory.

Thanks a lot!

Dick
Post Reply