zoukankan      html  css  js  c++  java
  • C# 解压文件

    /// <summary>
    /// 利用 WinRAR 进行解压缩
    /// </summary>
    /// <param name="path">文件解压路径(绝对)</param>
    /// <param name="rarPath">将要解压缩的 .rar 文件的存放目录(绝对路径)</param>
    /// <param name="rarName">将要解压缩的 .rar 文件名(包括后缀)</param>
    /// <returns>true 或 false。解压缩成功返回 true,反之,false。</returns>
    public bool UnRAR(string path, string rarPath, string rarName)
    {
    bool flag = false;
    string rarexe;
    RegistryKey regkey;
    Object regvalue;
    string cmd;
    ProcessStartInfo startinfo;
    Process process;
    try
    {
    regkey = Registry.LocalMachine.OpenSubKey(@"SOFTWAREMicrosoftWindowsCurrentVersionApp PathsWinRAR.exe");
    regvalue = regkey.GetValue("");
    rarexe = regvalue.ToString();
    regkey.Close();
    // rarexe = rarexe.Substring(1, rarexe.Length -1);
    Directory.CreateDirectory(path);

    //解压缩命令,相当于在要压缩文件(rarName)上点右键 ->WinRAR->解压到当前文件夹
    cmd = string.Format("x {0} {1} -y", rarName, path);
    startinfo = new ProcessStartInfo();
    startinfo.FileName = rarexe;
    startinfo.Arguments = cmd;
    startinfo.WindowStyle = ProcessWindowStyle.Hidden;
    startinfo.WorkingDirectory = rarPath;
    process = new Process();
    process.StartInfo = startinfo;
    process.Start();
    process.WaitForExit();
    if (process.HasExited)
    {
    flag = true;
    }
    process.Close();
    }
    catch (Exception e)
    {
    throw e;
    }
    return flag;
    }

  • 相关阅读:
    Collection LinkedList
    java 浅拷贝和深拷贝
    Collection ArrayList
    Java 集合
    Activity、Fragment、Service、View生命周期
    Android 事件分发机制
    retrofit2.0
    Android 知识图谱
    设计模式-代理模式
    多线程-lock
  • 原文地址:https://www.cnblogs.com/wlwenjie/p/5048517.html
Copyright © 2011-2022 走看看