zoukankan      html  css  js  c++  java
  • winrar 压缩文件方法

    问题描述:

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

      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)WinRARWinRAR.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 进行压缩
  • 相关阅读:
    day09_request&response学习笔记
    为什么浏览器User-agent(浏览器类型)总是有Mozilla字样?
    无效类字符串:ProgID: Excel.Application
    django2.0升级日记
    Kali Linux信息收集工具
    Kali Linux 工具使用中文说明书
    人手一份核武器
    五大常用算法【转发】
    ACCA AI来袭会议笔记
    2017 Gartner数据科学魔力象限出炉,16位上榜公司花落谁家?
  • 原文地址:https://www.cnblogs.com/xbding/p/4916863.html
Copyright © 2011-2022 走看看