I'm using the titled library from http://dotnetzip.codeplex.com/

I've zipped up a few folders and files zip.AddDirectory(path); where path is a fully qualified path to the folder I want to zip.

When I extract zip.ExtractAll(AppDomain.CurrentDomain.BaseDirectory + "Zipped"); I get the whole directory hierarchy in the "Zipped" folder.

That is fine if I want to restor files to the original folders, but I have a need to also extract to a user defined folder, and I'd like for just the relative for want of a better word folders to be extracted.

I'm having some trouble finding the explanation I want to say so I'll illustrate with a pic of the archive when I open with 7-Zip.

http://s18.postimg.org/3y71uby7d/Dot_Net_Zip1.jpg

So if the user selects C:\Extracted\ as the target folder I only want the files and folders I see to be extracted to that location without "C:\users\susan\documents\my doc...etc"

I hope you understand, and thank you for reading my question.

I should add that I tried zip.FlattenFoldersOnExtract = true; but that just extracts all files without any folder structure at all, which is not what I want.

Apparently that option isn't available in that library. One workaraound that I read about is to extract to a temp folder then move the specific folder where you want. The only other option, I'm aware of, is to modify the library to allow it explicitly.

Thanks.
That's a shame, in my mind it's very basic functionality and I thought I was just missing something.

Did a little more investigating for you. The answer seems to be in the creation not in the extraction. Using the .net ZipFile class I was able to get relative folders inside the archive by setting the Environment.CurrentDirectory to the parent folder of the folder I want to archive. I would imagine that this would work with the library you're using. If not, to use the .net classes you need to add a reference to System.IO.Compression.Filesystem and add the using command using System.IO.Compression; in your .cs file

If all your archives are created with relative folders, the worst that might happen is you'll have to create the parent folder structure you want, before extracting.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.