Unrar C#中的存档

Ale*_*kiy 3 .net c# compression command-line cmd

我想沉默提取.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);
Run Code Online (Sandbox Code Playgroud)

txt*_*elp 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();
Run Code Online (Sandbox Code Playgroud)

这将在后台启动WinRAR程序,并在文件完成取消后将控制权返回给您.

希望能有所帮助