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

    此方法适用于C盘windows文件夹中有WinRAR.exe文件

     /// 解压文件(不带密码) RAR压缩程序  返回解压出来的文件数量
            /// </summary>
            /// <param name="destPath">解压至目录</param>
            /// <param name="rarfilePath">压缩文件路径</param>
            public static int RARToFileEmail(string destPath, string rarfilePath)
            {
                try
                {
                    //组合出需要shell的完整格式
                    string shellArguments = string.Format("x -o+ "{0}" "{1}\"",
                        rarfilePath, destPath);
    
                    //用Process调用
                    using (Process unrar = new Process())
                    {
                        unrar.StartInfo.FileName = "winrar.exe";
                        unrar.StartInfo.Arguments = shellArguments;
                        //隐藏rar本身的窗口
                        unrar.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                        unrar.Start();
                        //等待解压完成
                        unrar.WaitForExit();
                        unrar.Close();
                    }
                    //统计解压后的目录和文件数
                    //string str=string.Format("解压完成,共解压出:{0}个目录,{1}个文件",
                    //    di.GetDirectories().Length, di.GetFiles().Length);
                    //return str;
                }
                catch (Exception ex)
                {
                    return 0;
                }
                DirectoryInfo di = new DirectoryInfo(destPath);
                int dirfileCount = 0;
                foreach (System.IO.DirectoryInfo dir in di.GetDirectories())
                {
                    dirfileCount++;
                }
                foreach (System.IO.FileInfo item in di.GetFiles())
                {
                    dirfileCount++;
                }
                return dirfileCount;
            }


  • 相关阅读:
    MYSQL-------安全等于<=>
    MYSQL-------转义简单说明
    Linux命令 sed
    长目录如何快速cd
    SQLAlchemy(增删改查)
    PostgreSQL主键约束混乱
    Python实现智能回复
    Python 腾讯云发送短信
    Python3 Twilio 发送短信
    Elasticsearch 多条件查询
  • 原文地址:https://www.cnblogs.com/snake-hand/p/3187086.html
Copyright © 2011-2022 走看看