using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Microsoft.Win32;
using System.Diagnostics; namespace CommonHelper
{
public class WinRARHelper
{
/// <summary>
/// 是否安装了Winrar
/// </summary>
/// <returns></returns>
static public bool Exists()
{
RegistryKey the_Reg =
Registry.LocalMachine.OpenSubKey(
@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WinRAR.exe");
return !string.IsNullOrEmpty(the_Reg.GetValue("").ToString());
} /// <summary>
/// 打包成Rar
/// </summary>
/// <param name="patch"></param>
/// <param name="rarPatch"></param>
/// <param name="rarName"></param>
public void CompressRAR(string patch, string rarPatch, string rarName)
{
string the_rar;
RegistryKey the_Reg;
object the_Obj;
string the_Info;
ProcessStartInfo the_StartInfo;
Process the_Process;
try
{
the_Reg =
Registry.LocalMachine.OpenSubKey(
@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WinRAR.exe");
the_Obj = the_Reg.GetValue("");
the_rar = the_Obj.ToString();
the_Reg.Close();
the_rar = the_rar.Substring(, the_rar.Length - );
Directory.CreateDirectory(patch);
//命令参数
//the_Info = " a " + rarName + " " + @"C:Test?70821.txt"; //文件压缩
the_Info = " a " + rarName + " " + patch + " -r"; ;
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;
}
}
/// <summary>
/// 解压
/// </summary>
/// <param name="unRarPatch"></param>
/// <param name="rarPatch"></param>
/// <param name="rarName"></param>
/// <returns></returns>
public string unCompressRAR(string unRarPatch, string rarPatch, string rarName)
{
string the_rar;
RegistryKey the_Reg;
object the_Obj;
string the_Info; try
{
the_Reg =
Registry.LocalMachine.OpenSubKey(
@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WinRAR.exe");
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(unRarPatch) == false)
{
Directory.CreateDirectory(unRarPatch);
}
the_Info = "x " + rarName + " " + unRarPatch + " -y"; ProcessStartInfo the_StartInfo = new ProcessStartInfo();
the_StartInfo.FileName = the_rar;
the_StartInfo.Arguments = the_Info;
the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
the_StartInfo.WorkingDirectory = rarPatch;//获取压缩包路径 Process the_Process = new Process();
the_Process.StartInfo = the_StartInfo;
the_Process.Start();
the_Process.WaitForExit();
the_Process.Close();
}
catch (Exception ex)
{
throw ex;
}
return unRarPatch;
}
}
} //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文件的更多相关文章

  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. C语言中 指针和数组

    C语言的数组表示一段连续的内存空间,用来存储多个特定类型的对象.与之相反,指针用来存储单个内存地址.数组和指针不是同一种结构因此不可以互相转换.而数组变量指向了数组的第一个元素的内存地址. 一个数组变 ...

  2. Java8的新特性

        Java 8主要新特性包括如下几点: 一.接口的默认方法和静态方法 Java 8版之前,接口只有抽象方法,而在Java 8,为接口新增了两种类型的方法. 第一种是默认方法:在Java 8中,可 ...

  3. PHP 使用get_class_methods()和array_diff() 兩個相同的類中方法差集

    进行二次开发时,习惯一份是原封不动的,一份正在修改.在修改时,发现修改的缺少原项目中的一些方法.本打算一个方法一个方法的对比,可是这样会比较花时间,划不来,PHP可以使用get_class_metho ...

  4. Jquery方法大全

    一.JQuery常用的方法 :(JQuery中90%都是方法,没有参数是获取,带参数是设置) $("#id").css('backgroundColor','blue'); .cs ...

  5. SecureCRT 7.3.4 安装以及破解

    1-9为 SecureCRT 7.3.4 安装图解:10-13是 SecureCRT 7.3.4 破解图解,心急的朋友可以直接向下拉. 以下是百度百科对 SecureCRT 的介绍: SecureCR ...

  6. [转]如何学好windows c++编程 学习精髓(收集,整理)

    以下是很多VC爱好者的学习经历,希望对大家有所帮助: 我记得我在网上是这么说的:先学win32的SDK,也就是API, 再学MFC,这么一来呢,就先有个基础,MFC是API的封装, 如果API用的熟了 ...

  7. Java_链表实现

    http://blog.csdn.net/a19881029/article/details/22695289

  8. 第二篇、HTML5新增标签

    <html> <head> <meta charset="UTF-8"> <title>html5新增的标签</title&g ...

  9. Git和CocoaPods的简单使用

    Git是一款免费.开源的分布式版本控制系统,还有一种SVN的开源的集中式版本控制系统.分布式相比于集中式的最大区别在于开发者可以提交到本地,每个开发者通过克隆(git clone),在本地机器上拷贝一 ...

  10. 【html】【7】基础布局初探

    当了解了上面的文章有一定基础后,开始尝试初步基础布局,可能不美观,但是要开始有布局框架思想 基础代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML ...