How to extract ZIP files with WinRAR command line?
Asked Answered
S

4

18

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.)

Subtract answered 22/8, 2009 at 9:56 Comment(2)
try using the UnRAR.dll COM library insteadRoentgenology
This is an old thread but I got here asking the same question. You can now use winrar.exe from the command line and it will work with zip files.Strom
U
48

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.

Un answered 12/10, 2013 at 18:16 Comment(1)
This works with both .zip and .rar archives. This is an answer.Mayo
Z
5

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.

Zanze answered 22/8, 2009 at 10:6 Comment(0)
S
1

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!

Spermous answered 15/5, 2012 at 9:3 Comment(1)
I don't think the OP wanted to write a new program with libs. He wants to use a ready-built app to unzip an archive file.Hyperpituitarism
F
0
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:

Fitzger answered 1/10, 2012 at 11:37 Comment(1)
I think i end up using 7z but the question was for using winrar not 7z.Subtract

© 2022 - 2024 — McMap. All rights reserved.