How to extract ZIP files with WinRAR command line?

user34537 picture user34537 · Aug 22, 2009 · Viewed 76.6k times · Source

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

Answer

user2874632 picture user2874632 · Oct 12, 2013

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.