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?
The standard folders are:
%ProgramFiles%\WinRAR
%ProgramFiles(x86)%\WinRAR
Rar.txt
to open it. This is the manual forRar.exe
, the console version of WinRAR.An appropriate Rar command line for your task would be:
The switch
-agYYYY-MM-DD
is responsible for creating in directoryF:\
archive files for example with namedata_2016-08-11.rar
.It is of course also possible to use
to create in
F:\
archive files with namedata_11.08.2016.rar
. But this is not advisable as the international date formatYYYY-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 formatDD.MM.YYYY
.See the answer on Simply compress 1 folder in batch with WinRAR command line? for difference on being specified
D:\data
orD:\data\
on Rar command line.For date string left to
data
separated with an underscore in archive file name it would be necessary to use a batch file which additionally renames the created RAR archive file using command REN.For understanding the used commands in the batch code above and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
echo /?
endlocal /?
for /?
ren /?
set /?
setlocal /?