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;
    }

  • 相关阅读:
    Oracle、Db2、SqlServer、MySQL 数据库插入当前系统时间
    Mybatis---在控制台打印sql语句
    多线程实现的四种方法
    Restful架构
    maven中的pom配置文件一——spring,mybatis,oracle,jstl,json,文件上传
    spring mvc配置
    spring的事务
    cglib动态代理
    jdk动态代理
    spring总结————AOP面向切面总结
  • 原文地址:https://www.cnblogs.com/wlwenjie/p/5048517.html
Copyright © 2011-2022 走看看