I have the folowing line in my batch script and try to use dot (".") instead of hypen ("-") between dates. However, while the following is working (with "-"):
Set TODAY=%date:~4,2%-%date:~7,2%-%date:~10,4%
when I change to dot ("."), it does not working:
Set TODAY=%date:~4,2%.%date:~7,2%.%date:~10,4%
I tried several escape character before dots e.g. \.
, but does not worked. Any idea?
Update: Here is the line that uses TODAY
variable:
rar a -r -ep1 %backup%\"%name%_%today%" %folder%
UPDATE: Here is the code that I use:
@echo off
setlocal
REM Specify the folder to compress below:
REM --------------------- Folder to compress -----------------------------------
set dir="D:\project\my-project\"
set name=my-project
set backup="D:\backup\project\"
set folder="D:\dev\project\my-project"
REM If you don't want to include the folder in backup file, add "\" at the end of the directory in folder param
REM ----------------------------------------------------------------------------
REM Path to WinRAR executable in Program Files. Change if location is different
REM ---------------------- WinRAR Directory ------------------------------------
set path="C:\Progra~2\WinRAR\WinRAR.Exe";%path%
REM ----------------------------------------------------------------------------
REM change working dir to dir specified above
cd %dir%
REM Replace space in hour with zero if it's less than 10
SET hr=%time:~0,2%
IF %hr% lss 10 SET hr=0%hr:~1,1%
REM This sets the date like this: mm-dd-yr-hhmmssss (includes 1/100 secs)
Set TODAY=%date:~10,4%-%date:~7,2%-%date:~4,2%_%hr%%time:~3,2%^%time:~6,2%%time:~9,2%
echo Folder to compress in *.RAR format:
echo %folder%
echo.
echo.
echo Compress all files in dir and subdirs into a single archive
echo.
echo.
echo Today's date and time will be added to the base filename
rar a -r -ep1 %backup%\"%name%_%today%" %folder%
pause
goto eof
endlocal
echo.
echo "Task Completed"
echo.
REM --------------------------- exit -----------------------------------------
:end
EXIT /B 0