Trying to use 7z compression in my code, but when it executes. Nothing is created

45 Views Asked by At

I am trying to use 7-zip in my code for mutiple gig folders. I tried to use the following code, but all it does is execute and nothing is created. No error codes and in that the folder I was trying to zip is 7 gig. It ran way to quick.

string strZipName = strInputFolder + ".7z";
string strWhatToZip = strInputFolder + "\\*";
Process p = Process.Start("7z", string.Format("\"{0}\" \"{1}\" a -t7z", @strZipName, @strWhatToZip));
p.WaitForExit();

I tried this code both with the @ and without, and both times nothing happened. Here is a screen shot of the debug session I ran, and if you look in the lower left corner. You can see the values of the variables. enter image description here

I then installed the nutg package aspose.zip, which actually did create a 7z file. But, it did not even come close to adding everything in the folder to the zip file before it completed. Again, there were no error messages.

Here is the complete code I was trying to use.

 class ArchiveFolders
 {
     public void Run7Zip(string strInputFolder, string strOutputFolder)
     {
        try
         {
             using (var archive = new SevenZipArchive(new SevenZipEntrySettings(new SevenZipLZMACompressionSettings())))
             {
                 Cursor.Current = Cursors.WaitCursor;
                 archive.CreateEntries(strInputFolder);
                 archive.Save("d:\\7Z_ManyFilesToCompress.7z");
                 Cursor.Current = Cursors.Default;
             }
             //7z a -t7z ".\Sadr - Narrow band filter.7z" ".\Sadr - Narrow band filter\*"
            /* string strZipName = strInputFolder + ".7z";
             string strWhatToZip = strInputFolder + "\\*";
             Process p = Process.Start("7z", string.Format("\"{0}\" \"{1}\" a -t7z", @strZipName, @strWhatToZip));
             p.WaitForExit();*/
         }
        catch (Exception ex) 
         {
             MessageBox.Show("archive failed");
         }

         MessageBox.Show("Data Folder has been archived ");
     }
 }

To be honest, I would rather use the 7z executable already installed on my machine. But I am not locked into that.

Any and all help is most appreciated.

0

There are 0 best solutions below