ma3stro ma3stro - 2 months ago 10x
Groovy Question

Winrar command line compress specific files with date in name depending on current date

I'm trying to compress SQL server backup (

) files using WinRAR command line command. Here's the command I use:

def fileType = "*.bak"

"cmd /c \"${rarCmd}\" a ${rarName} ${parameters} ${sourceDir} ${fileType}".execute()

I've got these files in my folder:


I only want to compress the files that are created today. So how should I modify the
variable in order to compress files containing
in their names?


Start WinRAR and click in menu Help on menu item Help topics. On tab Contents open list item Command line mode and click first on Command line syntax and you will see on opened help page:

WinRAR <command> -<switch1> -<switchN> <archive> <files...> <@listfiles...> <path_to_extract\>

Now let us compare this line with your code line:

"${rarCmd}" a ${rarName} ${parameters} ${sourceDir} ${fileType}

There is obviously already the mistake in your code to specify after the command first the archive file name and then the switches instead of first the switches and next the archive file name.

And there should be no space between ${sourceDir} and ${fileType}, but a backslash character.

Then open in contents list the sublist Switches and click on Alphabetic switches list. Build your parameters with using this list while reading it from top to bottom. The most interesting switches for you are most likely

-cfg- -ep1 -ibck -inul -m5 -r- -tl -tn23h -y --

-tn23h means last modification date of file is within the last 23 hours (file time newer than current time minus 23 hours). You could also use -tn1d for file last modified within 1 day.

In case of using console version Rar.exe instead of GUI version WinRAR.exe use the text file Rar.txt in program files folder of WinRAR as this is the manual for the console version. There are some switches different between console and GUI version.