如何使用 WinRAR 命令行解压 ZIP 文件?
在尝试提取 zip 文件时出现错误:
c:\path\name.zip 不是 RAR 压缩文件
没有要提取的文件
我的代码是:
p.StartInfo.FileName = @"C:\Program Files\WinRAR\rar.exe";
p.StartInfo.Arguments = string.Format("x -o- {2} \"{0}\" * \"{1}\"\\ ",
szFN,
outFolder,
passWord == null ? "" : string.Format("-p\"{0}\"", passWord));
GUI 版本可以提取 zip 和 7z 文件。
为什么这不起作用?如何提取 zip 和 7z 文件?
(注意:我有不同的 7zip 源代码。我想我可以合并两者,并且仅当文件具有 rar 扩展名时才使用上面的代码。但我不喜欢这个解决方案。)
While trying to extract zip files I get the error:
c:\path\name.zip is not RAR archive
No files to extract
My code is:
p.StartInfo.FileName = @"C:\Program Files\WinRAR\rar.exe";
p.StartInfo.Arguments = string.Format("x -o- {2} \"{0}\" * \"{1}\"\\ ",
szFN,
outFolder,
passWord == null ? "" : string.Format("-p\"{0}\"", passWord));
The GUI version can extract zip and 7z files.
Why doesn't this work? How can I extract zip and 7z files?
(NOTE: I have different source code for 7zip. I guess I can merge the two and only use the above when the file has a rar extension. But I don't like that solution.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
WinRAR的免费
unrar.exe
和控制台版本Rar.exe
仅支持RAR存档格式。这在Rar.exe
手册的第二段中有清楚的描述,它是 WinRAR 程序文件文件夹中的文本文件Rar.txt
。您需要使用
WinRar.exe
来代替,它还支持其他存档格式:示例:
语法、命令和开关GUI 版本
WinRAR.exe
在 WinRAR 的帮助中列出并描述。单击菜单中的帮助菜单项帮助主题,在帮助选项卡内容上打开项目命令行模式并阅读此项下列出的帮助页面。例如,仅
WinRAR.exe
支持但Rar.exe
不支持的开关-ibck
用于在后台运行提取,这意味着 GUI 版本WinRAR 使解压缩最小化为 Windows 系统托盘中的图标。Free
unrar.exe
and console versionRar.exe
of WinRAR support only RAR archive format. That is clearly described in second paragraph in manual forRar.exe
which is the text fileRar.txt
in program files folder of WinRAR.You need to use
WinRar.exe
instead which supports also other archive formats:Example:
The syntax, commands and switches for GUI version
WinRAR.exe
are listed and described in help of WinRAR. Click in menu Help on menu item Help topics, open on help tab Contents the item Command line mode and read the help pages listed under this item.For example the switch
-ibck
supported only byWinRAR.exe
but not byRar.exe
is for running the extraction in background which means GUI version of WinRAR makes the extraction minimized to an icon in Windows system tray.rar.exe
确实只能解压rar文件。它与 WinRAR 完全不一样。要在 .NET 中解压 ZIP 文件,您可能需要查看 DotNetZip 库。与 CSharpZipLib 不同,它具有与商业软件兼容的许可证。
如果您还需要支持 RAR,您可以将 UnRAR.dll 与 pinvoke 结合使用:
http://www.rarlab.com/rar_add.htm
http://www.rarlab.com/rar/UnRARDLL.exe
或者这个 .NET unRAR 库:
http://www.chilkatsoft.com/rar-dotnet.asp
也许 这个适用于 7zip。
rar.exe
can indeed only unpack rar files. It's not at all the same as WinRAR.For unpacking ZIP files in .NET, you might want to look at the DotNetZip library instead. It has a license compatible with commercial software, unlike CSharpZipLib.
If you need to support RAR as well, you can use UnRAR.dll with pinvoke:
http://www.rarlab.com/rar_add.htm
http://www.rarlab.com/rar/UnRARDLL.exe
Or this .NET unRAR libary:
http://www.chilkatsoft.com/rar-dotnet.asp
Perhaps this one for 7zip.
您可以使用
SevenZipSharp
或DotNetZip
库在您的应用程序中!但我会选择
SevenZipSharp
Lib,因为它支持 7- 支持的所有存档拉链!源代码和二进制文件都可以在链接中找到!
You can use either
SevenZipSharp
orDotNetZip
Library in your Application!But I will go for
SevenZipSharp
Lib as It supports all the archives supported by 7-Zip!Both Source and Binary are available in the Links!
进一步阅读参考:
References to further reading: