在C#中解压缩档案 [英] Unrar an archive in C#

查看:60
本文介绍了在C#中解压缩档案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想静默提取 .rar 归档文件。 .Net在IO.Compression中没有任何Rar类,因此我想使用cmd(比使用外部dll更好)。它提取,但不是在静默模式下。我在做什么错?

I want to silent extract of .rar archive. .Net haven't any Rar classes in IO.Compression, so i'd like to use cmd (it's better, than external dll). It extracts, but not in silent mode. What am I doing wrong?

const string source = "D:\\22.rar";
string destinationFolder = source.Remove(source.LastIndexOf('.'));
string arguments = string.Format(@"x -s ""{0}"" *.* ""{1}\""", source, destinationFolder);
Process.Start("winrar", arguments);


推荐答案

我自己使用了这段代码(添加了您的代码):

I use this bit of code myself (your code added):

const string source = "D:\\22.rar";
string destinationFolder = source.Remove(source.LastIndexOf('.'));
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.FileName = "\"C:\\Program Files\\WinRAR\\winrar.exe\"";
p.StartInfo.Arguments = string.Format(@"x -s ""{0}"" *.* ""{1}\""", source, destinationFolder);
p.Start();
p.WaitForExit();

这将在后台启动WinRAR程序,并在文件解压缩完成后将控制权返回给您- rar-ing。

That will launch the WinRAR program in the background and return control to you once the file has completed un-rar-ing.

希望有帮助的

这篇关于在C#中解压缩档案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆