如何使用7zip压缩目录?

时间:2014-08-07 05:07:14

标签: c# 7zip

我正在尝试使用7zip压缩目录,但它不起作用,并且都没有提供错误/异常

代码

 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();

有人可以指导我吗?我正在关注链接http://www.dotnetperls.com/7-zipCOMMAND LIST FOR 7ZIP

我已直接尝试使用命令提示符,但没有命令对我有效!

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

任何人都可以帮我找到上述命令中的错误!!!

1 个答案:

答案 0 :(得分:2)

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

这适合我。

所以C#代码中的等价参数应该是:

pCompress.Arguments = "a -tzip \"" + targetCompressName + "\" \"" + sourceCompressDir +"\"";