Extract files without saved path

May 24, 2010 at 4:24 PM
Edited May 24, 2010 at 4: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

 

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

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

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

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

Many Thank's
Claudio
Coordinator
May 24, 2010 at 4:56 PM

yes. Rename the entry before calling Extract.

e.FileName = "directory_C\file.txt";
e.Extract(targetDir);

 

May 25, 2010 at 9: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 8: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 11: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

Claudio

May 26, 2010 at 12:35 PM
Edited May 26, 2010 at 12:35 PM
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 3:58 PM

John,

it run perfectly,

thank you very mutch.

Claudio