Unrar C#中的存档

时间:2014-05-10 08:12:47

标签: c# .net command-line cmd compression

我想隐藏.rar存档的摘录。 .Net没有IO.Compression中的任何Rar类,所以我想使用cmd(它比外部dll更好)。它提取,但不是静音模式。我做错了什么?

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

4 个答案:

答案 0 :(得分:6)

我自己使用这段代码(你的代码已添加):

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程序,并在文件完成取消后将控制权返回给您。

希望可以提供帮助

答案 1 :(得分:1)

或者,您可以在应用程序中嵌入名为unRAR的工具,这是WinRAR开发人员开发的小型可执行文件(official download)。

此实用程序是免费的,因此您的用户无需拥有WinRAR许可即可使用您的应用程序。 :)它可以使用 txtechhelp 描述的相同方式执行。

答案 2 :(得分:0)

使用SharpCompress https://github.com/adamhathcock/sharpcompress/blob/master/USAGE.md 还有一个易于安装的nuget软件包。

Install-Package sharpcompress -Version 0.22.0

答案 3 :(得分:0)

使用NUnrar,还有一个nuget软件包,易于安装。

Install-Package nunrar

NUnrar.Archive.RarArchive.WriteToDirectory(fileName,destinationfileName);