Tutorial 04: Working with command line tools: RAR compression/decompression

March 22nd, 2007

Fileaze can batch compress and decompress using the Zip and Unzip actions but what about other formats? We’re fans of WinRAR and the RAR format and Fileaze happens to work great with the command line. In this fourth tutorial we’ll see how easy it is to enable batch RAR compression and decompression through Fileaze and the rar.exe command line tool!

Note: this tutorial presumes that you followed the previous ones and are able to perform the operations explained there. It also assumes you have a copy of the rar.exe command line tool: this is included with WinRAR and can be found inside the installation directory. If you don’t have WinRAR you can download a trial version following the link at the end of this tutorial.

Working with command line tools in Fileaze is as easy as adding the “Command” action to a batch job, but there are some things to consider to avoid pitfalls.

Suppose you want to compress with RAR all the files in a folder:

2007-03-22_124121.jpg

All you need to do is to create a job and add that folder as a source:

2007-03-22_124740.jpg

Note: We’ll keep things simple here. From the previous tutorials you already know you can select multiple sources, from your disk, an FTP server and many others, that you can filter in many ways and that you have options for keeping the original paths or not. If those concepts are not clear to you, we suggest you to walk through the previous tutorials, here we’ll deal with a simple folder source to focus on the command line operations.

The next step is to create the command action that invokes the rar.exe tool but before doing it let’s add some considerations. As any other executable file, when Fileaze runs it runs “in its own directory”, meaning that if Fileaze is installed in “C:\Program Files\Resolware\Fileaze”, then any command issued by Fileaze will need to be in the same directory unless you don’t specify its full path. Moving commands around is seldom a good idea because they could depend on external files and libraries so we suggest to specify the full path to the command line tool you’re invoking. In case of the rar.exe command, the full path could be something like “C:\Program Files\WinRAR\rar.exe” and you’ll need to type it entirely, just saying “rar.exe” won’t find the tool and the job will fail!

On to the options we need on the command line. Suppose you want to add files to the RAR archive “C:\backup.rar” without including the original files’ paths in the archive. For this, we need to pass rar.exe the ‘a’ command and the ‘-ep’ switch.

Note: Rar.exe is very flexible and powerful and it supports a huge number of commands and switches. For a complete list consult the rar.exe help on the command line

The command line with options would then be

C:\Program Files\WinRAR\rar.exe a -ep c:\backup.rar

but it still lacks the last parameter: the filename to add to the archive. Being a batch job, the RAR command will run for all files found in the sources so we need to pass a different filename at every invocation of the command. This is easily done by entering %FILENAME% as the filename parameter at the end of the command line: this variable will be substituted with the current filename at every invocation of the command and the filename will be automatically enclosed in double quotes to prevent problems with paths containing spaces.

The complete command line then is:

C:\Program Files\WinRAR\rar.exe a -ep c:\backup.rar %FILENAME%

and we can use it to create our action.

Just create the action as usual, selecting Command as the action type

2007-03-22_124121_cr.jpg

and fill in the parameters in the action editor:

2007-03-22_144902.jpg

You’re done. Save the action and the job, run the job and after it finishes the backup.rar file will be created in the destination folder (C:\ in our case):

2007-03-22_145126.jpg

Opening the file with WinRAR shows what we expected:

2007-03-22_145314.jpg

On the same line, you can create batch decompression jobs (for example to automatically unpack RAR archives residing in multiple folders) or mix the command action with the FTP/email capabilities or archive bit techniques you learned of in the previous tutorials, including scheduling the job for unattended operation even without Fileaze running.