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

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

问题描述

我试图用拉链的7zG.exe命令行/ 7Z文件夹。我有代码工作的文件,但没有文件夹。可能有人请告诉我使用的7z命令行来压缩文件夹的正确方法?下面是仅用于文件的工作示例代码。每当我尝试运行此代码7zip的显示一个消息说:无效的参数

 字符串SOURCENAME =Folder\Folder1; 
字符串目标名称=Example.gz;

// 1
//初始化过程的信息。
//
的ProcessStartInfo P =新的ProcessStartInfo();
p.FileName =7zG.exe;

// 2
//使用7-ZIP
//在引号后面指定=归档和-tgzip = gzip的
//然后目标文件在引号
//
p.Arguments =一个-tgzip \源文件+目标名称+\\+ SOURCENAME +\-mx = 9;
p.WindowStyle = ProcessWindowStyle.Hidden;

// 3,
//启动进程并等待它退出
//
过程X =的Process.Start(P);
x.WaitForExit();


解决方案

述明的评论部分,你应该使用 7za.exe



这的链接给你一个完整的例子行



您的代码看起来像这样

 字符串SOURCENAME =Folder\Folder1; 
字符串目标名称=Example.gz;

的ProcessStartInfo P =新的ProcessStartInfo();
//第一个变化
p.FileName =7za.exe;
//第二个变化
p.Arguments =一个-tzip \+目标名称+\\+ SOURCENAME +\-mx = 9;
p.WindowStyle = ProcessWindowStyle.Hidden;
过程X =的Process.Start(对);
x.WaitForExit();


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

解决方案

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

This link gives you a complete example line

Your code will look like this:

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

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

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