1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.IO;
  5. using Microsoft.Win32;
  6. using System.Diagnostics;
  7.  
  8. namespace CommonHelper
  9. {
  10. public class WinRARHelper
  11. {
  12. /// <summary>
  13. /// 是否安装了Winrar
  14. /// </summary>
  15. /// <returns></returns>
  16. static public bool Exists()
  17. {
  18. RegistryKey the_Reg =
  19. Registry.LocalMachine.OpenSubKey(
  20. @"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WinRAR.exe");
  21. return !string.IsNullOrEmpty(the_Reg.GetValue("").ToString());
  22. }
  23.  
  24. /// <summary>
  25. /// 打包成Rar
  26. /// </summary>
  27. /// <param name="patch"></param>
  28. /// <param name="rarPatch"></param>
  29. /// <param name="rarName"></param>
  30. public void CompressRAR(string patch, string rarPatch, string rarName)
  31. {
  32. string the_rar;
  33. RegistryKey the_Reg;
  34. object the_Obj;
  35. string the_Info;
  36. ProcessStartInfo the_StartInfo;
  37. Process the_Process;
  38. try
  39. {
  40. the_Reg =
  41. Registry.LocalMachine.OpenSubKey(
  42. @"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WinRAR.exe");
  43. the_Obj = the_Reg.GetValue("");
  44. the_rar = the_Obj.ToString();
  45. the_Reg.Close();
  46. the_rar = the_rar.Substring(, the_rar.Length - );
  47. Directory.CreateDirectory(patch);
  48. //命令参数
  49. //the_Info = " a " + rarName + " " + @"C:Test?70821.txt"; //文件压缩
  50. the_Info = " a " + rarName + " " + patch + " -r"; ;
  51. the_StartInfo = new ProcessStartInfo();
  52. the_StartInfo.FileName = the_rar;
  53. the_StartInfo.Arguments = the_Info;
  54. the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
  55. //打包文件存放目录
  56. the_StartInfo.WorkingDirectory = rarPatch;
  57. the_Process = new Process();
  58. the_Process.StartInfo = the_StartInfo;
  59. the_Process.Start();
  60. the_Process.WaitForExit();
  61. the_Process.Close();
  62. }
  63. catch (Exception ex)
  64. {
  65. throw ex;
  66. }
  67. }
  68. /// <summary>
  69. /// 解压
  70. /// </summary>
  71. /// <param name="unRarPatch"></param>
  72. /// <param name="rarPatch"></param>
  73. /// <param name="rarName"></param>
  74. /// <returns></returns>
  75. public string unCompressRAR(string unRarPatch, string rarPatch, string rarName)
  76. {
  77. string the_rar;
  78. RegistryKey the_Reg;
  79. object the_Obj;
  80. string the_Info;
  81.  
  82. try
  83. {
  84. the_Reg =
  85. Registry.LocalMachine.OpenSubKey(
  86. @"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WinRAR.exe");
  87. the_Obj = the_Reg.GetValue("");
  88. the_rar = the_Obj.ToString();
  89. the_Reg.Close();
  90. //the_rar = the_rar.Substring(1, the_rar.Length - 7);
  91.  
  92. if (Directory.Exists(unRarPatch) == false)
  93. {
  94. Directory.CreateDirectory(unRarPatch);
  95. }
  96. the_Info = "x " + rarName + " " + unRarPatch + " -y";
  97.  
  98. ProcessStartInfo the_StartInfo = new ProcessStartInfo();
  99. the_StartInfo.FileName = the_rar;
  100. the_StartInfo.Arguments = the_Info;
  101. the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
  102. the_StartInfo.WorkingDirectory = rarPatch;//获取压缩包路径
  103.  
  104. Process the_Process = new Process();
  105. the_Process.StartInfo = the_StartInfo;
  106. the_Process.Start();
  107. the_Process.WaitForExit();
  108. the_Process.Close();
  109. }
  110. catch (Exception ex)
  111. {
  112. throw ex;
  113. }
  114. return unRarPatch;
  115. }
  116. }
  117. }
  118.  
  119. //RAR参数:
  120.  
  121. //一、压缩命令
  122. //1、将temp.txt压缩为temp.rarrar a temp.rar temp.txt
  123. //2、将当前目录下所有文件压缩到temp.rarrar a temp.rar *.*
  124. //3、将当前目录下所有文件及其所有子目录压缩到temp.rarrar a temp.rar *.* -r
  125. //4、将当前目录下所有文件及其所有子目录压缩到temp.rar,并加上密码123rar a temp.rar *.* -r -p123
  126.  
  127. //二、解压命令
  128. //1、将temp.rar解压到c:\temp目录rar e temp.rar c:\temprar e *.rar c:\temp(支持批量操作)
  129. //2、将temp.rar解压到c:\temp目录,并且解压后的目录结构和temp.rar中的目录结构一
  130.  
  131. //压缩目录test及其子目录的文件内容
  132. //Wzzip test.zip test -r -P
  133. //WINRAR A test.rar test -r
  134.  
  135. //删除压缩包中的*.txt文件
  136. //Wzzip test.zip *.txt -d
  137. //WinRAR d test.rar *.txt
  138.  
  139. //刷新压缩包中的文件,即添加已经存在于压缩包中但更新的文件
  140. //Wzzip test.zip test -f
  141. //Winrar f test.rar test
  142.  
  143. //更新压缩包中的文件,即添加已经存在于压缩包中但更新的文件以及新文件
  144. //Wzzip test.zip test -u
  145. //Winrar u test.rar test
  146.  
  147. //移动文件到压缩包,即添加文件到压缩包后再删除被压缩的文件
  148. //Wzzip test.zip -r -P -m
  149. //Winrar m test.rar test -r
  150.  
  151. //添加全部 *.exe 文件到压缩文件,但排除有 a或b
  152. //开头名称的文件
  153. //Wzzip test *.exe -xf*.* -xb*.*
  154. //WinRAR a test *.exe -xf*.* -xb*.*
  155.  
  156. //加密码进行压缩
  157. //Wzzip test.zip test
  158. //-s123。注意密码是大小写敏感的。在图形界面下打开带密码的压缩文件,会看到+号标记(附图1)。
  159. //WINRAR A test.rar test -p123
  160. //-r。注意密码是大小写敏感的。在图形界面下打开带密码的压缩文件,会看到*号标记(附图2)。
  161.  
  162. //按名字排序、以简要方式列表显示压缩包文件
  163. //Wzzip test.zip -vbn
  164. //Rar l test.rar
  165.  
  166. //锁定压缩包,即防止未来对压缩包的任何修改
  167. //无对应命令
  168. //Winrar k test.rar
  169.  
  170. //创建360kb大小的分卷压缩包
  171. //无对应命令
  172. //Winrar a -v360 test
  173.  
  174. //带子目录信息解压缩文件
  175. //Wzunzip test -d
  176. //Winrar x test -r
  177.  
  178. //不带子目录信息解压缩文件
  179. //Wzunzip test
  180. //Winrar e test
  181.  
  182. //解压缩文件到指定目录,如果目录不存在,自动创建
  183. //Wzunzip test newfolder
  184. //Winrar x test newfolder
  185.  
  186. //解压缩文件并确认覆盖文件
  187. //Wzunzip test -y
  188. //Winrar x test -y
  189.  
  190. //解压缩特定文件
  191. //Wzunzip test *.txt
  192. //Winrar x test *.txt
  193.  
  194. //解压缩现有文件的更新文件
  195. //Wzunzip test -f
  196. //Winrar x test -f
  197.  
  198. //解压缩现有文件的更新文件及新文件
  199. //Wzunzip test -n
  200. //Winrar x test -u
  201.  
  202. //批量解压缩文件
  203. //Wzunzip *.zip
  204. //WinRAR e *.rar

C#解压、压缩RAR文件的更多相关文章

  1. ubuntu解压/压缩rar文件

    一般通过默认安装的ubuntu是不能解压rar文件的,只有在安装了rar解压工具之后,才可以解压.其实在ubuntu下安装rar解压工具是非常简单的,只需要两个步骤就可以迅速搞定.ubuntu 下ra ...

  2. linux命令解压压缩rar文件

    一.widonds下打包rar文件并上传 yum install lrzsz rz test.rar 二.下载并安装rar软件 2.1 下载 mkdir -p /home/oldboy/tools c ...

  3. linux命令解压压缩rar文件的详细步骤

    参考文件:https://www.cnblogs.com/qinglin/p/9007939.html

  4. linux下解压压缩rar文件

    http://download.csdn.net/detail/hnust_xiehonghao/6679893   下载地址 1. 下载软件 以rarlinux-3.8.0 for linux为例, ...

  5. centos7解压压缩zip文件

    一.安装支持ZIP的工具 yum install -y unzip zip 二.解压zip文件 unzip 文件名.zip 二. 压缩一个zip文件 zip 文件名.zip 文件夹名称或文件名称

  6. C# .NET 使用第三方类库DotNetZip解压/压缩Zip文件

    dotNetZip on CodePlex: http://dotnetzip.codeplex.com/ 详细的可以看源代码……总之感觉比SharpZipLib好用.而且DotNetZip支持VB, ...

  7. linux解压/压缩文件

    1.*.tar 用 tar –xvf 解压  2.*.gz 用 gzip -d或者gunzip 解压  3.*.tar.gz和*.tgz 用 tar –xzf 解压  4.*.bz2 用 bzip2 ...

  8. C# 上传RAR文件 解压 获取解压后的文件名称

    此方法适用于C盘windows文件夹中有WinRAR.exe文件 if (fileExt.ToUpper() == ".RAR") { string zpath = Server. ...

  9. Linux解压/压缩命令——tar、gz、tar.gz、tgz、bz2、tar.bz2、Z、zip、rar、lha

    .tar 解包:tar -xvf FileName.tar 打包:tar -cvf FileName.tar DirName ——————————————— .gz 解压1:gunzip FileNa ...

  10. python用模块zlib压缩与解压字符串和文件的方法

    摘自:http://www.jb51.net/article/100218.htm Python标准模块中,有多个模块用于数据的压缩与解压缩,如zipfile,gzip, bz2等等. python中 ...

随机推荐

  1. [引]LINQ to XML 类概述

    本文转自:http://msdn.microsoft.com/zh-cn/library/bb387023.aspx 本主题提供 System.Xml.Linq 命名空间中 LINQ to XML 类 ...

  2. 分布式算法(一致性Hash算法)

    一.分布式算法 在做服务器负载均衡时候可供选择的负载均衡的算法有很多,包括: 轮循算法(Round Robin).哈希算法(HASH).最少连接算法(Least Connection).响应速度算法( ...

  3. Smarty中一些标签的使用

    Smarty中的标签和php中的标签不一样 foreach标签{foreach   from=$goods(变量名) key='键,不带$' item='值,不带$'}中间的显示内容{/foreach ...

  4. Android系统中的dp和px的转换

    android系统中DP和SP的转化:1.首先分析TypedValue.java 可以调用以下代码获得dp的值 TypedValue.applyDimension(TypedValue.COMPLEX ...

  5. ClassLoader和Reflect

    什么情况下使用ClassLoader来加载类?其实这个问题应该问,什么时候使用import来加载类,不能使用import的,就只能使用ClassLoader了. 使用import的条件: 1.必须是存 ...

  6. 解决 Zabbix agent on [HOSTNAME] is unreachable for 5 minutes

    今天中午发现zabbix陆续出现Zabbix agent on [HOSTNAME] is unreachable for 5 minutes问题,开始是只是寥寥几台,没太在意,吃了顿饭回来发现一大堆 ...

  7. ASP.NET 发送email

    首先添加命名空间 using System.Net.Mail; /// <summary> /// 发送邮件 /// </summary> /// <param name ...

  8. 【转】querystring传递中文出现乱码的问题

    原帖地址:http://www.cnblogs.com/Fly-sky/archive/2009/04/22/1441015.html 现象:近期项目中用到查询字符串传值,如果传递的是英文一切正常,但 ...

  9. Mysql 流程控制

    流程控制 分支结构 if分支结构 语法:     if 条件then         -- 语句体     else         -- 缺省语句体     end if; 示例: 循环结构 whi ...

  10. 第48条:如果需要精确的答案,请避免使用float和double

    float和double主要为了科学计算和工程计算而设计,执行二进制浮点运算,这是为了在广泛的数值范围上提供较为精确的快速近似计算而精心设计的.然而,它们没有提供完全精确的结果,所以不适合用于需要精确 ...