0

I have a folder containing a million zip files which I need to extract. Two ways I have tried:

Way 1: Use the 7-zip exe file and System.Diagnostic Process as follows

 ProcessStartInfo p = new ProcessStartInfo();
 p.FileName = "7za.exe" 
 p.Arguments = "e " + sourceName; // sourceName is the name of the zip file
 p.WindowStyle = ProcessWindowStyle.Hidden;
 Process x = Process.Start(p);
 x.WaitForExit();

Way 2: Use the 7z.dll and SevenZipExtractor as follows

 SevenZipExtractor.SetLibraryPath(@"C:\Program Files\7-Zip\7z.dll");
 SevenZipExtractor zipFile = new SevenZipExtractor("inv1_0.zip");
 zipFile.ExtractArchive(@"c:\projects\extractor\extractor\bin\debug\inv1_0.dat");

Two things here:

a) Way 1 works perfectly fine. Way 2 doesn't work. Give the error "SevenZip.SevenZipArchiveException: Invalid archive: open/read error!". Can someone suggest why this could be happening when way 1 is giving the correct extracted file?

b) Since there are a million zip files, I am worried about using Way 1 : as in the Process. How expensive is to loop through a million zip files and use process for each one of them. I would really like to use Way 2 but for some reason it gives the exception.

sinelaw
  • 16,205
  • 3
  • 49
  • 80
blue piranha
  • 3,706
  • 13
  • 57
  • 98
  • 1
    Option 3: Write a batch file. http://stackoverflow.com/questions/138497/batch-scripting-iterating-over-files-in-a-directory – P.Brian.Mackey Nov 21 '13 at 20:22
  • 1
    what is the full path to inv1_0.zip? Have you tried specifying the full path to the file? – iamkrillin Nov 21 '13 at 20:23
  • @iamkrillin its all in the same folder. invalid file isn't the error here. – blue piranha Nov 21 '13 at 20:25
  • Is it all files that are failing to unzip or just this one particular file? – Kim Nov 21 '13 at 20:26
  • Option 4: use SharpZipLib (http://www.icsharpcode.net/opensource/sharpziplib/), I've used this in the past for handling large quantities for zip files, it's very simple to use, and never ran into this kind of weird problems :) – Jason Nov 21 '13 at 20:31
  • it looks like this error msg is very generic, The full message from the source code is: "Invalid archive: open/read error! Is it encrypted and a wrong password was provided? If your archive is an exotic one, it is possible that SevenZipSharp has no signature for its format and thus decided it is TAR by mistake." – iamkrillin Nov 21 '13 at 20:38

1 Answers1

0

You can't avoid the cost of unzipping 1,000,000 files, but you can choose the way it'll cost you - processor usage, or time. If you don't want to lock your main thread, let a secondary thread handle the file processing for you.

Options:

But that doesn't seem to be your issue at all. It seems to me that SevenZipExtractor is behaving in a different way than the standalone .exe. I would obviously stick to the first (working) option until I figured out what's wrong with the 2nd approach.

You may also want to pay a visit to sevenzipsharp's CodePlex discussion group.

Community
  • 1
  • 1
OnoSendai
  • 3,960
  • 2
  • 22
  • 46