C#调用RAR压缩与解压
public void RARsave(string rarPatch, string rarFiles,string patch,string rarName)
{
String the_rar;
RegistryKey the_Reg;
Object the_Obj;
String the_Info;
ProcessStartInfo the_StartInfo;
Process the_Process;
try
{
the_Reg = Registry.ClassesRoot.OpenSubKey(@"Applications\\WinRAR.exe\\Shell\\Open\\Command");
the_Obj = the_Reg.GetValue("");
the_rar = the_Obj.ToString();
the_Reg.Close();
the_rar = the_rar.Substring(1, the_rar.Length - 7);
if (!Directory.Exists(patch))
Directory.CreateDirectory(patch);
//命令参数
//the_Info = " a c:\\test.rar a.txt -r"; //文件压缩
the_Info = string.Format(" a -df {0}\\{1} {2} -r", patch, rarName, rarFiles);// " a " + rarName + " " + patch;
the_StartInfo = new ProcessStartInfo();
the_StartInfo.FileName = the_rar;
the_StartInfo.Arguments = the_Info;
the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
//打包文件存放目录
the_StartInfo.WorkingDirectory = rarPatch;
the_Process = new Process();
the_Process.StartInfo = the_StartInfo;
the_Process.Start();
the_Process.WaitForExit();
the_Process.Close();
}
catch (Exception ex)
{
throw ex;
}
}
public string unRAR(string rarPath, string rarName, string unRarPath)
{
String the_rar;
RegistryKey the_Reg;
Object the_Obj;
String the_Info;
ProcessStartInfo the_StartInfo;
Process the_Process;
try
{
the_Reg = Registry.ClassesRoot.OpenSubKey(@"Applications\\WinRAR.exe\\Shell\\Open\\Command");
the_Obj = the_Reg.GetValue("");
the_rar = the_Obj.ToString();
the_Reg.Close();
the_rar = the_rar.Substring(1, the_rar.Length - 7);
if (!Directory.Exists(unRarPath + "\\" + rarName.Substring(0, rarName.LastIndexOf(".")-1)))
Directory.CreateDirectory(unRarPath + "\\" + rarName.Substring(0, rarName.LastIndexOf(".")-1));
the_Info = string.Format("x {0} {1}\\{2} -y", rarName, unRarPath, rarName.Substring(0, rarName.LastIndexOf(".")-1));
the_StartInfo = new ProcessStartInfo();
the_StartInfo.FileName = the_rar;
the_StartInfo.Arguments = the_Info;
the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
the_StartInfo.WorkingDirectory = rarPath;//获取压缩包路径
the_Process = new Process();
the_Process.StartInfo = the_StartInfo;
the_Process.Start();
the_Process.WaitForExit();
the_Process.Close();
}
catch (Exception ex)
{
throw ex;
}
return "";//Server.MapPath(unRarPatch);
}
public string unRAR(string rarPath, string rarName, string unRarPath, string unRarPathName)
{
String the_rar;
RegistryKey the_Reg;
Object the_Obj;
String the_Info;
ProcessStartInfo the_StartInfo;
Process the_Process;
try
{
the_Reg = Registry.ClassesRoot.OpenSubKey(@"Applications\\WinRAR.exe\\Shell\\Open\\Command");
the_Obj = the_Reg.GetValue("");
the_rar = the_Obj.ToString();
the_Reg.Close();
the_rar = the_rar.Substring(1, the_rar.Length - 7);
//if (!Directory.Exists(unRarPath + "\\" + unRarPathName))
// Directory.CreateDirectory(unRarPath + "\\" + unRarPathName);
//the_Info = string.Format("x {0} {1}\\{2} -y", rarName, unRarPath, unRarPathName);
if (!Directory.Exists(unRarPath ))
Directory.CreateDirectory(unRarPath);
the_Info = string.Format("x {0} {1} -y", rarName, unRarPath);
the_StartInfo = new ProcessStartInfo();
the_StartInfo.FileName = the_rar;
the_StartInfo.Arguments = the_Info;
the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
the_StartInfo.WorkingDirectory = rarPath;//获取压缩包路径
the_Process = new Process();
the_Process.StartInfo = the_StartInfo;
the_Process.Start();
the_Process.WaitForExit();
the_Process.Close();
}
catch (Exception ex)
{
throw ex;
}
return "";//Server.MapPath(unRarPatch);
}
RARsave("c:\\emrbs", "1.txt 2.txt", "c:\\test", "test.rar");
unRAR("d:\\","f.rar","d:\\ftest");
/压缩程序安装路径
RAR参数:
一、压缩命令
1、将temp.txt压缩为temp.rarrar a temp.rar temp.txt
2、将当前目录下所有文件压缩到temp.rarrar a temp.rar *.*
3、将当前目录下所有文件及其所有子目录压缩到temp.rarrar a temp.rar *.* -r
4、将当前目录下所有文件及其所有子目录压缩到temp.rar,并加上密码123rar a temp.rar *.* -r -p123
二、解压命令
1、将temp.rar解压到c:/temp目录rar e temp.rar c:/temprar e *.rar c:/temp(支持批量操作)
2、将temp.rar解压到c:/temp目录,并且解压后的目录结构和temp.rar中的目录结构一
压缩目录test及其子目录的文件内容
Wzzip test.zip test -r -P
WINRAR A test.rar test -r
删除压缩包中的*.txt文件
Wzzip test.zip *.txt -d
WinRAR d test.rar *.txt
刷新压缩包中的文件,即添加已经存在于压缩包中但更新的文件
Wzzip test.zip test -f
Winrar f test.rar test
更新压缩包中的文件,即添加已经存在于压缩包中但更新的文件以及新文件
Wzzip test.zip test -u
Winrar u test.rar test
移动文件到压缩包,即添加文件到压缩包后再删除被压缩的文件
Wzzip test.zip -r -P -m
Winrar m test.rar test -r
添加全部 *.exe 文件到压缩文件,但排除有 a或b
开头名称的文件
Wzzip test *.exe -xf*.* -xb*.*
WinRAR a test *.exe -xf*.* -xb*.*
加密码进行压缩
Wzzip test.zip test
-s123。注意密码是大小写敏感的。在图形界面下打开带密码的压缩文件,会看到+号标记(附图1)。
WINRAR A test.rar test -p123
-r。注意密码是大小写敏感的。在图形界面下打开带密码的压缩文件,会看到*号标记(附图2)。
按名字排序、以简要方式列表显示压缩包文件
Wzzip test.zip -vbn
Rar l test.rar
锁定压缩包,即防止未来对压缩包的任何修改
无对应命令
Winrar k test.rar
创建360kb大小的分卷压缩包
无对应命令
Winrar a -v360 test
带子目录信息解压缩文件
Wzunzip test -d
Winrar x test -r
不带子目录信息解压缩文件
Wzunzip test
Winrar e test
解压缩文件到指定目录,如果目录不存在,自动创建
Wzunzip test newfolder
Winrar x test newfolder
解压缩文件并确认覆盖文件
Wzunzip test -y
Winrar x test -y
解压缩特定文件
Wzunzip test *.txt
Winrar x test *.txt
解压缩现有文件的更新文件
Wzunzip test -f
Winrar x test -f
解压缩现有文件的更新文件及新文件
Wzunzip test -n
Winrar x test -u
批量解压缩文件
Wzunzip *.zip
WinRAR e *.rar
C#调用RAR压缩与解压的更多相关文章
- java压缩文件解压:调用WinRAR5命令强于自己写代码实现
最近,手上维护着一个几年前的系统,技术是用的JSP+Strust2,系统提供了rar和zip两种压缩格式的解压功能,后台是用java实现的 1.解压rar格式,采用的是java-unrar-0.3.j ...
- 【JNI】OPUS压缩与解压的JNI调用(.DLL版本)
OPUS压缩与解压的JNI调用(.DLL版本) 一.写在开头: 理论上讲,这是我在博客园的第一篇原创的博客,之前也一直想找个地方写点东西,把最近做的一些东西归纳总结下,但是一般工程做完了一高兴就把东西 ...
- Linux学习之CentOS(十九)------linux 下压缩与解压之 tar、gzip、bzip2、zip、rar
将文件存储到归档文件中或者从归档文件中获取原始文件,以及为文件创建归档文件 tar [option] [modifiers] [file-list] 参数 file-list是tar进行归档和提取的文 ...
- linux中tar命令(打包、压缩、解压)、zip和unzip、rar多种压缩文件
一.名词解释 打包:将一大堆文件或目录变成一个总的文件[tar命令] 压缩:将一个大的文件通过一些压缩算法变成一个小文件[gzip,bzip2等] Linux中很多压缩程序只能针对一个文件进行压缩,这 ...
- XML序列化 判断是否是手机 字符操作普通帮助类 验证数据帮助类 IO帮助类 c# Lambda操作类封装 C# -- 使用反射(Reflect)获取dll文件中的类型并调用方法 C# -- 文件的压缩与解压(GZipStream)
XML序列化 #region 序列化 /// <summary> /// XML序列化 /// </summary> /// <param name="ob ...
- C#调用7z实现文件的压缩与解压
1.关于7z 首先在这里先介绍一下7z压缩软件,7z是一种主流的 压缩格式,它拥有极高的压缩比.在计算机科学中,7z是一种可以使用多种压缩算法进行数据压缩的档案格式.主要有以下特点: 来源且模块化的组 ...
- linux下文件压缩与解压操作
对于刚刚接触Linux的人来说,一定会给Linux下一大堆各式各样的文件名给搞晕.别个不说,单单就压缩文件为例,我们知道在Windows下最常见的压缩文件就只有两种,一是,zip,另一个是.rap.可 ...
- Linux下常用压缩格式的压缩与解压方法
.tar 解包: tar xvf FileName.tar 打包:tar cvf FileName.tar DirName (注:tar是打包,不是压缩!) --------------------- ...
- linux下tar gz bz2 tgz z等众多压缩文件的压缩与解压方法
Linux下最常用的打包程序就是tar了,使用tar程序打出来的包我们常称为tar包,tar包文件的命令通常都是以.tar结尾的.生成tar包后,就可以用其它的程序来进 行压缩了,所以首先就来讲讲ta ...
随机推荐
- JBoss QuickStart之深入
EJB-AsynchronousEJB中提供异步调用的方法. "A session bean can expose methods with asynchronous client invo ...
- 【转】监听按钮除OnClick外其他事件的方法,附简易改编的UIButton类
http://lib.csdn.net/article/unity3d/38463 作者:IceFantasyLcj 大家好,我是雨中祈雨.一直以来,CSDN都是我最好的编程助手.这是我在CSDN的第 ...
- HTML:document.activeElement
今天遇到一个很郁闷的问题: document.activeElement获取当前获得焦点的元素,在chrome总是得到body,后来经过试验得到结果如下: document.activeElement ...
- js事件模型与自定义事件
JavaScript 一个最简单的事件模型,需要有事件绑定与触发,还有事件删除. var eventModel = { list: {}, bind: function () { var args = ...
- JavaScript中一些常用的方法整理
当前时间和输入时间比较 var timeLong = Date.parse(new Date());//当前时间var t1 = Date.parse($("#returnTime2&quo ...
- 常用数据存储集合与Map
一.常见的数据存储实现 二.遍历 1.集合 新循环 迭代器 Iterator Iterator<?> it = C.iterator(); // 问.取.删 it.hasNext() ...
- JMeter学习-023-JMeter 命令行(非GUI)模式详解(一)-执行、输出结果及日志、简单分布执行脚本
前文 讲述了JMeter分布式运行脚本,以更好的达到预设的性能测试(并发)场景.同时,在前文的第一章节中也提到了 JMeter 命令行(非GUI)模式,那么此文就继续前文,针对 JMeter 的命令行 ...
- win7下开启telnet命令
win7下开启telnet命令 win7上telnet这条命令默认被关闭了. 开启telnet方法如下: 一,打开控制面版 二,选择程序 三,选择打开或关闭windows功能 在弹出窗口中把 Teln ...
- Python 字符串反转
方法一: 切片的方法 a = "hello"b = len(a)i = 1c = ""while i<=b: d = a[b-i] c += d i+=1 ...
- front-end plugin, generate pdf with html5 and jquery
http://www.jqcool.net/jquery-jspdf.html[from this site] <html> <head></head> <s ...