zoukankan      html  css  js  c++  java
  • 利用好压在C#程序里实现RAR格式的压缩和解压功能

    public static void UnZipFile(string strFromFilePath, string strToFilePath)
    {
    Process proc = new Process();
    try
    {
    proc.StartInfo.FileName = "cmd.exe";
    proc.StartInfo.UseShellExecute = false;
    proc.StartInfo.RedirectStandardInput = true;
    proc.StartInfo.RedirectStandardOutput = true;
    proc.StartInfo.RedirectStandardError = true;
    proc.StartInfo.CreateNoWindow = true;
    proc.Start();
    string strZipPath = System.Windows.Forms.Application.StartupPath + "\HaoZip\HaoZipC.exe";
    string dosLine = strZipPath + " e " + strFromFilePath + " -o" + strToFilePath;
    proc.StandardInput.WriteLine(dosLine);
    proc.StandardInput.WriteLine("exit");
    while (!proc.HasExited)
    {
    proc.WaitForExit(1000);
    }
    List<string> lstAllIp = new List<string>();
    string strInfo = proc.StandardOutput.ReadToEnd();
    System.IO.File.Delete(strFromFilePath);
    }
    catch
    {

    }
    }
    public static void ZipFile(string strFromFilePath, string strToFilePath)
    {
    Process proc = new Process();
    try
    {
    proc.StartInfo.FileName = "cmd.exe";
    proc.StartInfo.UseShellExecute = false;
    proc.StartInfo.RedirectStandardInput = true;
    proc.StartInfo.RedirectStandardOutput = true;
    proc.StartInfo.RedirectStandardError = true;
    proc.StartInfo.CreateNoWindow = true;
    proc.Start();
    string strZipPath = System.Windows.Forms.Application.StartupPath + "\HaoZip\HaoZipC.exe";
    string dosLine = strZipPath + " a -tzip " + strToFilePath + " " + strFromFilePath;
    proc.StandardInput.WriteLine(dosLine);
    proc.StandardInput.WriteLine("exit");
    while (!proc.HasExited)
    {
    proc.WaitForExit(1000);
    }
    List<string> lstAllIp = new List<string>();
    string strInfo = proc.StandardOutput.ReadToEnd();
    System.IO.File.Delete(strFromFilePath);
    }
    catch
    {

    }
    }

    上述两个方法的运行要求:1、需要把好压安装后的HaoZip目录拷贝到程序根目录 2、需要添加引用 using System.Diagnostics;

  • 相关阅读:
    Sunnypig闯三角关
    送给圣诞夜的贺卡
    uva 1592(NEERC 2009 STL)
    uva 297(传递闭包 WF 1996)
    hdu 4190(二分)
    uva 3592 (MST, kruskal)
    uva 11997 (基础数据结构)
    hdu 2680 (Dijkstra)
    hdu 4568(状态压缩dp)
    hdu 4582 (树上的贪心)
  • 原文地址:https://www.cnblogs.com/wjx-blog/p/5885404.html
Copyright © 2011-2022 走看看