2013-05-03 73 views
0

我想在我的c#代码中包含一个Process.Start行,用于从归档中提取单个文件。特别是我正在寻找命令行执行的样子。如何使用winrar从档案中提取一个文件?

I.E.我有一个档案Test.rar其中有文件picture.png以及一堆其他文件。如何获取picture.png到我选择的目的地?

谢谢。

回答

1

使用unrar.exe这样的:

unrar.exe X test.rar C:\目的地

Process process = new Process(); 
process.StartInfo.FileName = "unrar.exe"; 
process.StartInfo.Arguments = "x test.rar C:\Destination"; 
process.Start(); 
process.WaitForExit(); 
+0

这是unrar整个文件吗?我只想从归档文件中取出一个文件,因为整个文件需要很长时间。 – fsnot 2013-05-03 23:21:51

+0

您可以使用n 指定您只需要名为file的文件。 unrar.exe x npicture.png test.rar C:\ Destination。在命令提示符下运行不带参数的unrar.exe以查看所有选项。 – Arsen 2013-05-03 23:24:04

+0

太棒了!这正是我需要的。感谢提示在cmd中运行unrar。我真的没有想到它):如果存档中有多个同名的文件,怎么办?它只是n <文件位置\文件>? – fsnot 2013-05-03 23:37:01

1

刚刚揭开序幕传递适当的参数的过程。你可以像处理其他文件一样处理文件。

Process process = new Process(); 
process.StartInfo.FileName = @"C:\MyPathToWinRar\winnrar.exe"; 
process.StartInfo.Arguments = @"unrar x c:\yourfile.rar fileToExtract.png c:\extractfolder\"; 
process.Start(); 
process.WaitForExit(); 

欲了解更多关于winrar args的信息,请点击这里; http://comptb.cects.com/2503-using-the-winrar-command-line-tools-in-windows

P.S.如果您决定不使用Process,有一些库。 https://stackoverflow.com/questions/11737/net-library-to-unzip-zip-and-rar-files

+0

非常感谢!这是我正在寻找的。如果在rar文件目录中的不同位置有多个相同名称的文件,我只需使用:“unrar x c:\ yourfile.rar location \ fileToExtract.png c:\ extractfolder \”? – fsnot 2013-05-03 23:32:20

+0

@ user2348593我相信如此,但是你必须通过尝试找出它,因为我只是阅读文档,没有winrar在我正在处理的补充。 – evanmcdonnal 2013-05-03 23:47:05

相关问题