如何使用7zip压缩目录

本文关键字:压缩 7zip 何使用 | 更新日期: 2023-09-27 18:17:04

我试图用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-zip和7ZIP命令列表

我已经尝试过直接使用命令提示符,但没有一个命令适合我!

1)C:> C: '7ziptest/7za.exe 7za -tzip " C: '7ziptest'TestFolder.zip" " C: '7ziptest'tes .exetfolder "

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

    Error:
    Incorrect command line

2)C:> C: '7ziptest/7za.exe 7za -tzip " C: '7ziptest'TestFolder.zip" " C: '7ziptest'tes .exetfolder ' "

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

    Error:
    Incorrect command line

3)C:> C: '7ziptest/7za.exe 7za -tzip " C: '7ziptest'TestFolder.zip" " C: '7ziptest'tes .exetfolder '"mx = 9

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

    Error:
    Incorrect command line

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

如何使用7zip压缩目录

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

这个适合我。

所以c#代码中的等效参数应该是:
pCompress.Arguments = "a -tzip '"" + targetCompressName + "'" '"" + sourceCompressDir +"'"";