ITeye博客

C# 如何读取rar压缩包里面的文件信息

dnanhui · 2013-01-22 17:08 · .net · 编程语言 · Markdown

private string RunCmd(string command) { //实例一个Process类,启动一个独立进程 Process p = new Process(); p.StartInfo.FileName = "cmd.exe"; p.StartInfo.Arguments = "/c "+"\""+System.Windows.Forms.Application.StartupPath+"\\r ar.exe" +"\""+ command; //设定程式执行参数 p.StartInfo.UseShellExecute = false; //关闭Shell的使用 p.StartInfo.RedirectStandardInput = true; //重定向标准输入 p.StartInfo.RedirectStandardOutput = true; //重定向标准输出 p.StartInfo.RedirectStandardError = true; //重定向错误输出 p.StartInfo.CreateNoWindow = true; //设置不显示窗口 p.Start(); //启动 string retstr=p.StandardOutput.ReadToEnd(); p.WaitForExit(); p.Close(); return retstr; //从输出流取得命令执行结果 } /// /// 获得RAR信息 /// /// 包文件路径 /// private Hashtable CheckRar(string rar_path) { string strcmd1 = string.Format(" lb {0} ", rar_path); string outcmd_string1 = RunCmd(strcmd1).Replace("\r\n", "|"); outcmd_string1 = outcmd_string1.Remove(outcmd_string1.LastIndexOf('|')); string strcmd2 = string.Format(" l {0} ", rar_path); string outcmd_string2 = RunCmd(strcmd2); string[] strfilenames = outcmd_string1.Split('|'); int filecount = strfilenames.Length; string[] strfilesizes = new string[filecount]; for (int i = 0; i < filecount; i++) { string filesize = outcmd_string2.Substring(outcmd_string2.IndexOf(strfilenames[i]) + strfilenames[i].Length).Trim(); filesize = filesize.Substring(0, filesize.IndexOf(" ")); strfilesizes[i] = filesize; } Hashtable ht_rar = new Hashtable(); for (int i = 0; i < filecount; i++) { ht_rar.Add(strfilenames[i],strfilesizes[i]); } return ht_rar; }

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。