C#調用WinRAR實現壓縮與解壓縮

來源:互聯網
上載者:User

using System.Diagnostics;
.............

  {   //************ 壓 縮 *************
   string strF="iis6.log";  
   string strR="newiis";   //壓縮包檔案名稱
   Process p = new Process();
   p.StartInfo.FileName="Winrar.exe";
   p.StartInfo.CreateNoWindow=false;

//   p.StartInfo.Arguments=" a -r "+strR+" "+strF;   //預設壓縮到RAR
//   p.StartInfo.Arguments=" a -afzip "+strR+" "+strF;  //壓縮到Zip
//   p.StartInfo.Arguments=" m "+strR+" "+strF;     //壓縮到RAR並刪除原檔案
//   p.StartInfo.Arguments=" a -p123456 "+strR+" "+strF;  //密碼為123456

   
  {  //************ 解 壓 縮 ************* 

//   p.StartInfo.Arguments=" x "+strR+" "+strF;  //從RAR解壓縮,檔案名稱要一致
//   p.StartInfo.Arguments=" x -p123456 "+strR+" "+strF;  //解壓加密的RAR
   
   /*    " x -o+" 覆蓋已經存在的檔案
          " x -o-" 不覆蓋已經存在的檔案
          " x " + strzipPath + "  free1.txt "' + strtxtPath  只從壓縮包中解壓出free1.txt,其它檔案不予解壓
          " -y"   對所有詢問回應為"是",即發生錯誤也不快顯視窗
          " -cl"   轉換檔名為小寫字母    */

   p.Start();
   if p.HasExited
   {
    int iExitCode = p.ExitCode;
    if (iExitCode == 0)
    {     MessageBox.Show( "正常完成");    }
    else
    {     MessageBox.Show(" 有錯完成");    }
   }
  }  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.