Tutorial – Using WinRAR command-line tools

When you install WinRar, two command-line tools are also installed, rar.exe and unrar.exe. They will be located in C:\Program Files\WinRAR by default.

Here’s an example of how to extract the contents of a single rar file:

  1. open a command prompt
    (Windows 2000/xp, choose start->programs->accessories->Command Prompt)
  2. add the winrar tools to the path:
    c:\> set path="C:\Program Files\WinRAR\";%path%
  3. switch to the directory where you want your files to extract to:
    c:\> cd /d z:\some_folder
  4. use unrar to extract the file:
    z:\some_folder> unrar e c:\some_rar_file.rar

You can of course wrap all of this into a batch file that loops through all of the .rar files in a folder. Here’s a quicky sample (doesn’t handle spaces in .rar file names):

@REM ------- BEGIN demo.cmd ----------------
@echo off
set path="C:\Program Files\WinRAR\";%path%
for /F %%i in ('dir /s/b *.rar') do call :do_extract "%%i"
goto :eof

echo %1
mkdir %~1.extracted
pushd %~1.extracted
unrar e %1

REM ------- END demo.cmd ------------------

For detailed information on windows batch files, please see:

OSX documentation [new]

  1. Open a terminal window.
  2. In the terminal window, navigate to the folder containing your .rar files:
    cd /<path-to-files>
  3. Run the following command:
    for i in *.rar; do unrar e "$i"; done

    Note: “unrar” may need to be replaced with the full path to your unrar executable. For example, if unrar is installed in /usr/local/bin, the command becomes:

    for i in *.rar; do /usr/local/bin/unrar e "$i"; done

    OSX unrar is available from RAR Labs, here

3 Responses to Tutorial – Using WinRAR command-line tools

  1. Lelala says:

    Thanks for that article, i’ve played more than two hours but coudln’t get it done – thanks to yuor article, its now OK :-)

  2. Matthew says:

    Instead of bloating the path, you could also symlink the .exe files to a common and suitable location already in the path. If you are still running XP you could physically copy them there, and again after each update.

    • earlye says:

      This is true. However, the script we supply has @setlocal before modifying the path, so the change does not affect the user’s environment variables once the script completes.