Extract files without saved path

May 24, 2010 at 3:24 PM
Edited May 24, 2010 at 3:30 PM

Hello, can I extract my zip files into another directory wich is not the same as I saved it ?

This is the directory structure saved into file.zip


--> dir A
   --> sub dir A
      --> file.txt

I want save file.txt into this sample directories structure :
   --> file.txt
If use e.Extract(targetDir, ExtractExistingFileAction.OverwriteSilently)
passing directory_C as targetDir the final result is :

  --> dir A 
     --> sub dir A 
        --> file.txt 

It's wrong for my use. Can you help me ?

Many Thank's
May 24, 2010 at 3:56 PM

yes. Rename the entry before calling Extract.

e.FileName = "directory_C\file.txt";


May 25, 2010 at 8:20 AM

Thank you for your reply but giving an error :


 foreach (ZipEntry e in zip)

                        // http://dotnetzip.codeplex.com/Thread/View.aspx?ThreadId=213650
                        FileInfo f = new FileInfo(e.FileName);
                        e.FileName = Path.Combine(targetDir, f.Name);

                        e.Extract(targetDir, ExtractExistingFileAction.OverwriteSilently);
                        logger.Trace("File {0} successfull unzipped on {1}", fileZipName, targetDir);

If I modify the filename into zip collection I have this error:
failed: System.ApplicationException : Collection was modified; enumeration operation may not execute.

Any other help ?

Bye, Claudio


May 26, 2010 at 7:54 AM

I read many many post ... :o(

there is same issue on :

Aug 2009    http://dotnetzip.codeplex.com/Thread/View.aspx?ThreadId=83773

Feb 2009    http://dotnetzip.codeplex.com/Thread/View.aspx?ThreadId=83773


May 26, 2010 at 10:26 AM

I need the required feature.

I can't use Rename the entry before calling Extract. because it throw an exception "collection was modified".

I switched now on http://sevenzipsharp.codeplex.com/

Simply settings false to PreserveDirectoryStructure flag I obtained my result correct.

Than you all, bye


May 26, 2010 at 11:35 AM
Edited May 26, 2010 at 11:35 AM
Instead of foreach (ZipEntry e in zip) Try foreach (ZipEntry e in zip.EntriesSorted) This is what I used as a workaround and it works great. Didn't need to change any other line of code.
May 26, 2010 at 2:58 PM


it run perfectly,

thank you very mutch.