2

I am trying to zip directory with 7zip but it not works, and neither gives error/exception

Code

 string sourceCompressDir = @"c:\7ziptest\TestFolder";
 string targetCompressName = @"c:\7ziptest\TestFolder.zip";
 ProcessStartInfo pCompress = new ProcessStartInfo();
 pCompress.FileName = "7za.exe";

 //Not working for below arguments
 pCompress.Arguments = "7z a " + targetCompressName + " " + sourceCompressDir";

 pCompress.WindowStyle = ProcessWindowStyle.Hidden;
 pCompress.UseShellExecute = false;
 Process x = Process.Start(pCompress);
 x.WaitForExit();

Could anyone guide me? I am following link http://www.dotnetperls.com/7-zip AND COMMAND LIST FOR 7ZIP

I have tried directly with command prompt but none command works for me !

1) C:>c:\7ziptest/7za.exe 7z a -tzip "c:\7ziptest\TestFolder.zip" "c:\7ziptest\tes tfolder"

    7-Zip (A) 4.42  Copyright (c) 1999-2006 Igor Pavlov  2006-05-14


    Error:
    Incorrect command line

2) C:>c:\7ziptest/7za.exe 7z a -tzip "c:\7ziptest\TestFolder.zip" "c:\7ziptest\tes tfolder\"

    7-Zip (A) 4.42  Copyright (c) 1999-2006 Igor Pavlov  2006-05-14


    Error:
    Incorrect command line

3) C:>c:\7ziptest/7za.exe 7z a -tzip "c:\7ziptest\TestFolder.zip" "c:\7ziptest\tes tfolder\" -mx=9

    7-Zip (A) 4.42  Copyright (c) 1999-2006 Igor Pavlov  2006-05-14


    Error:
    Incorrect command line

Could anyone help me to find what is wrong in above commands !!!

Sam
  • 423
  • 1
  • 8
  • 22
  • 2
    The first parameter in 1), 2) and 3) is `7z`. This is not a parameter, it's a executable file (you are trying to use `7za.exe` and you put it in `FileName`). `Arguments` should contain only parameters. – Marek Grzenkowicz Aug 11 '14 at 06:30
  • You can use the SDK from 7z (LZMA SDK, you can download it from 7z web site). http://stackoverflow.com/questions/7646328/how-to-use-the-7z-sdk-to-compress-and-decompress-a-file – Jaime García Pérez Aug 11 '14 at 06:49

1 Answers1

2

D:\>7za a -tzip arch.zip "D:\dirName"

This works for me.

So the equivalent arguments in C# code should be:

pCompress.Arguments = "a -tzip \"" + targetCompressName + "\" \"" + sourceCompressDir +"\"";
cshu
  • 4,814
  • 23
  • 36