Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top