问题描述:

  我要一些大的文件进行压缩,看了网上有很多类拟的写法。但在我这都存在两个问题。

  1.就是他们都是通过注册表找到rar的exe目录。我安装好winrar后,虽然注册表有,但那个目录一直报一个错。

  2.压缩文件中包含了上几层的目录。

问题分析:

  1.针对第一个问题其实你就指定你机器的目录就行了。何必那么麻烦。

  2.加一个对应的指令就行了。

具体代码如下:

用如下代码前先安装好winrar

/// <summary>
/// 利用 WinRAR 进行压缩
/// </summary>
/// <param name="strRarPatch">待压缩文件目录</param>
/// <param name="strRarFiles">待压缩文件路径(绝对全路径)</param>
/// <param name="strPatch">压缩目录(绝对路径)</param>
/// <param name="strRarName">压缩后的文件名</param>
public static void SaveRar(string strRarPatch, string strRarFiles, string strPatch, string strRarName)
{
String strThe_Info;
ProcessStartInfo the_StartInfo;
Process the_Process;
try
{
if (!Directory.Exists(strPatch))
{
Directory.CreateDirectory(strPatch);
}
//命令参数 df:删除原文件 ep:从名称中排除路径
//如果压缩文件不指定具体文件夹,只给一个压缩文件,默认会跟原文件放在同一目录
strThe_Info = string.Format(" a -df -ep {0}\\{1} {2} -r", strPatch, strRarName, strRarFiles);
the_StartInfo = new ProcessStartInfo();
//从配置信息中找到对应winrar安装目录的exe对应绝对路径:如:C:\Program Files (x86)\WinRAR\WinRAR.exe
string strWinRarPath =System.Configuration.ConfigurationSettings.AppSettings["WinRarPath"].ToString();
the_StartInfo.FileName = @strWinRarPath;
the_StartInfo.Arguments = strThe_Info;
the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
//打包文件存放目录
the_StartInfo.WorkingDirectory = strRarPatch;
the_Process = new Process();
the_Process.StartInfo = the_StartInfo;
the_Process.Start();
the_Process.WaitForExit();
the_Process.Close();
}
catch (Exception ex)
{
throw ex;
}
}

利用winrar 进行压缩

winrar 压缩文件方法的更多相关文章

  1. 文件上传,服务端压缩文件方法,重点是png与gif图片的压缩,保证了透明度与动画

    /// <summary> /// 上传文件帮助类 /// </summary> public class ImageUploadHelper { #region SaveVi ...

  2. linux 解压 WinRAR 压缩文件

    1.Download rar for linux wget http://www.rarlab.com/rar/rarlinux-x64-5.5.b1.tar.gz 2.Configure rar t ...

  3. 【转载】使用Winrar对压缩文件进行加密,并且给定解压密码

    有时候我们从网上下载的压缩包文件,如.rar文件.zip文件等,解压的时候需要输入解压密码才可顺利解压,否则解压失败.其实像这种情况,是压缩包制作者在压缩文件的时候对压缩文件进行了加密,输入了压缩包解 ...

  4. "xxxx".zip:这个压缩文件格式未知或者数据已经被损坏,打不开压缩文件,总出现这个提示的解决方法

    从网上下载了一些压缩文件,有时解压时会出现“这个压缩文件格式未知或者数据已经被损坏”或“未找到压缩文件”的提示. 造成的原因有两种: 一.网站上的压缩文件本来就是坏的. 1.你可以尝试可以使用WINR ...

  5. 使用zip压缩文件夹方法

    最近使用MapGis对.MPJ工程文件文件裁剪后,要对裁剪后的图形文件.ML,.MT,.MP,.MPJ文件打包,在网上找到7zip,Zlib的库,虽然都有源码,但是Zlib库中的使用没找到文件压缩的函 ...

  6. java对压缩文件进行加密,winrar和好压 直接输入解密密码来使用

    <!-- https://mvnrepository.com/artifact/net.lingala.zip4j/zip4j --> <dependency> <gro ...

  7. 用Winrar批量解压缩有密码文件方法,只需输入一次密码

    老王上传的文件多是RAR压缩格式的, 每个系列下载完,都20多集,解压缩的时候要一个一个的输入密码,太浪费时间. 1) 把下载的需要解压缩的文件统一放到一个文件夹下. 2) 启动winrar程序 (从 ...

  8. 利用WinRAR命令行压缩文件或文件夹

    压缩文件夹winrar.exe a -ag -k -r -s -ibck c:/bak.rar c:/dat/ 压缩多个文件winrar a -ag -ibck bak.rar filename1 f ...

  9. 批处理命令调用WINRAR对文件进行压缩

    命令: winrar a 参数  压缩后的文件 压缩源文件 如压缩apk文件,代码如下 echo apk文件不能直接下载,所以压缩apk成rar来下载 d: cd D:\Program Files\W ...

随机推荐

  1. mybatis--MapperScannerConfigurer

    一般我们这样配置 <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryB ...

  2. ionic实现双击返回键退出软件

    1.首先要安装cordova插件:插件地址:cordova plugin add https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin.git ...

  3. some smart

    1.ca.laplanete.mobile.pageddragdropgridhttps://github.com/mrKlar/PagedDragDropGridPagedDragDropGrid ...

  4. 转: Android入门及效率开发

    评注: android第三方开源框架介绍不错 转:https://segmentfault.com/a/1190000004495351 入门 Android官方培训课程中文版:http://huka ...

  5. 移动端1px细线的处理

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. 每天一道LeetCode--434. Number of Segments in a String

    Count the number of segments in a string, where a segment is defined to be a contiguous sequence of ...

  7. php学习笔记2--安装apache遇到的问题

    下载apache之后,以管理员身份运行cmd:1.httpd -k install2.httpd -k start出现无法运行的问题,可能的原因是443端口已被占用.在我的机器中是因为安装了VMwar ...

  8. Part 32 Abstract classes in c#

  9. Jquery操作radio,checkbox,select表单操作实现代码

    一 .Select jQuery获取Select选择的Text和Value: 1. $("#select_id").change(function(){//code...}); / ...

  10. shell获取本地ip的三种方法

    第一种方法:ifconfig|grep inet |awk '{print $2}'|sed '2d'|awk -F : '{print $2}'第二种方法:ifconfig|grep inet|se ...