c# - 如何使用 7zip 压缩目录?

标签 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 t文件夹”

    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 t文件夹\"

    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 t文件夹\"-mx=9

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


    Error:
    Incorrect command line

谁能帮我看看上面的命令有什么问题!!!

最佳答案

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

这对我有用。

因此 C# 代码中的等效参数应该是:

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

关于c# - 如何使用 7zip 压缩目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25174564/

相关文章:

c# - 如何使用 MVC 路由多语言 URL

c# - C# 中的类型相等性检查

c# - 如何使用 Entity Framework Core 2.0 检索 JSON 存储过程的结果?

Azure管道,自托管代理,我可以使用脚本中的zip实用程序吗

powershell - 无法创建输出目录错误: 7zip

c# - 如何检查文件是否通过 7zip 受密码保护?

c# - 调整 MenuStrip 的宽度

c# - 使用 XSLT 转换序列化的 .net 对象

batch-file - CMD 批处理和 7z : Capture the progress of the extraction

Python错误: Cannot find the file specified