I have folder D:\data
with lots of subfolders and files and I want to archive this folder with a batch file to a specified directory with current date added in archive file name, e.g. F:\11.08.2016_data
.
My command line is so far:
"C:\Program Files\WinRAR\rar.exe" a -ep1 -r "data" "D:\data"
This command line creates RAR archive file data.rar
in folder My Documents
.
How can I add date and change the archiving directory?
How to build a WinRAR command line?
<command>
in text editor or command prompt window by most suitable command letter for the task.-<switch1> -<switchN>
in text editor or command prompt window by those switches which are useful for the task.How to build a RAR command line?
%ProgramFiles%\WinRAR
%ProgramFiles(x86)%\WinRAR
Rar.txt
to open it. This is the manual for Rar.exe
, the console version of WinRAR.An appropriate Rar command line for your task would be:
"%ProgramFiles%\WinRAR\rar.exe" a -agYYYY-MM-DD -cfg- -ep1 -inul -m5 -r -y "F:\data_.rar" "D:\data\"
The switch -agYYYY-MM-DD
is responsible for creating in directory F:\
archive files for example with name data_2016-08-11.rar
.
It is of course also possible to use:
"%ProgramFiles%\WinRAR\rar.exe" a -agDD.MM.YYYY -cfg- -ep1 -inul -m5 -r -y "F:\data_.rar" "D:\data\"
This command line creates in F:\
archive files with name data_11.08.2016.rar
. But this is not advisable as the international date format YYYY-MM-DD
has the advantage that the files listed alphabetically sorted by name are automatically also listed by date which is not the case with date format DD.MM.YYYY
.
See the answer on Simply compress 1 folder in batch with WinRAR command line? for difference on being specified D:\data
or D:\data\
on Rar command line.
A +
must be inserted between -ag
and date format string for date left to data
separated with an underscore in archive file name.
Date in international format YYYY-MM-DD
at beginning of RAR file name:
"%ProgramFiles%\WinRAR\rar.exe" a -ag+YYYY-MM-DD -cfg- -ep1 -inul -m5 -r -y "F:\_data.rar" "D:\data\"
Date in format DD.MM.YYYY
at beginning of RAR file name:
"%ProgramFiles%\WinRAR\rar.exe" a -ag+DD.MM.YYYY -cfg- -ep1 -inul -m5 -r -y "F:\_data.rar" "D:\data\"