我想静默提取.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);
最佳答案
我自己使用了这段代码(您添加的代码):
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 程序,并在文件完成解压缩后将控制权返回给您。
希望对你有帮助
关于c# - 在 C# 中解压缩存档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23578704/