如何使用 WinRAR 命令行解压 ZIP 文件?

发布于 2024-08-03 01:52:28 字数 510 浏览 13 评论 0原文

在尝试提取 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

世态炎凉 2024-08-10 01:52:28

WinRAR的免费unrar.exe和控制台版本Rar.exe仅支持RAR存档格式。这在 Rar.exe 手册的第二段中有清楚的描述,它是 WinRAR 程序文件文件夹中的文本文件 Rar.txt

您需要使用 WinRar.exe 来代替,它还支持其他存档格式:

[path\winrar.exe] x [开关] [zip 文件的路径] [要提取的文件,. 对于所有文件] [要提取到的路径文件夹]

示例:

"%ProgramFiles%\WinRAR\winrar.exe" x -ibck c:\file.zip *.* c:\folder\

语法、命令和开关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 for Rar.exe which is the text file Rar.txt in program files folder of WinRAR.

You need to use WinRar.exe instead which supports also other archive formats:

[path\winrar.exe] x [switches] [path to zip file] [files to extract, . for all files] [path folder to extract to]

Example:

"%ProgramFiles%\WinRAR\winrar.exe" x -ibck c:\file.zip *.* c:\folder\

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 by WinRAR.exe but not by Rar.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.

别闹i 2024-08-10 01:52:28

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.

爱你是孤单的心事 2024-08-10 01:52:28

您可以使用 SevenZipSharpDotNetZip 库在您的应用程序中!

但我会选择 SevenZipSharp Lib,因为它支持 7- 支持的所有存档拉链!

源代码和二进制文件都可以在链接中找到!

You can use either SevenZipSharp or DotNetZip 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!

南薇 2024-08-10 01:52:28
for /f "tokens=*" %G in ('dir /on /b "D:\BACKUP_DATI\EXCEL\OPER*.ZIP"') do "C:\Program Files\7-Zip\7z.exe" x  "..\%G" –aoa

进一步阅读参考:

for /f "tokens=*" %G in ('dir /on /b "D:\BACKUP_DATI\EXCEL\OPER*.ZIP"') do "C:\Program Files\7-Zip\7z.exe" x  "..\%G" –aoa

References to further reading:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文