我正在尝试使用 7zG.exe 的命令行来压缩/7z 文件夹。我的代码适用于文件,但不适用于文件夹。有人可以告诉我使用 7z 命令行压缩文件夹的正确方法吗?以下是仅适用于文件的示例代码。每当我尝试运行此代码时,7zip 都会显示一个消息框,显示“参数无效”
string sourceName = "Folder\Folder1";
string targetName = "Example.gz";
// 1
// Initialize process information.
//
ProcessStartInfo p = new ProcessStartInfo();
p.FileName = "7zG.exe";
// 2
// Use 7-zip
// specify a=archive and -tgzip=gzip
// and then target file in quotes followed by source file in quotes
//
p.Arguments = "a -tgzip \"" + targetName + "\" \"" + sourceName + "\" -mx=9";
p.WindowStyle = ProcessWindowStyle.Hidden;
// 3.
// Start process and wait for it to exit
//
Process x = Process.Start(p);
x.WaitForExit();
如评论部分所述,您应该使用7za.exe
This link http://blog.enrii.com/2007/06/06/zip-a-folder-using-command-line/给你一个完整的示例行
您的代码将如下所示:
string sourceName = "Folder\Folder1";
string targetName = "Example.gz";
ProcessStartInfo p = new ProcessStartInfo();
//first change
p.FileName = "7za.exe";
//second change
p.Arguments = "a -tzip \"" + targetName + "\" \"" + sourceName + "\" -mx=9";
p.WindowStyle = ProcessWindowStyle.Hidden;
Process x = Process.Start(p);
x.WaitForExit();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)