7z 命令行压缩文件夹 [英] 7z command line to compress folders

查看:43
本文介绍了7z 命令行压缩文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 7zG.exe 的命令行压缩/7z 文件夹.我的代码适用于文件,但不适用于文件夹.有人可以告诉我使用 7z 命令行压缩文件夹的正确方法吗?这是仅适用于文件的示例代码.每当我尝试运行此代码时,7zip 都会显示一个消息框,上面写着无效参数"

I am trying to zip/7z folders using the command line of 7zG.exe. The code I have works for files but not folders. Could someone please show me the correct way using 7z command line to compress folders? Here is the sample code that works for files only. Whenever I try running this code 7zip shows a messagebox saying "Invalid Parameter"

string sourceName = "FolderFolder1";
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

as stated in to comment section, you are supposed to use 7za.exe

链接为您提供了完整的示例行

This link gives you a complete example line

您的代码将如下所示:

string sourceName = "FolderFolder1";
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();

这篇关于7z 命令行压缩文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆