Code: Select all
@echo off
set "hr=%time:~0,2%"
if exist "Archive*.tib" if "%hr:~0,1%" equ " " set "hr=0%hr:~1,1%"
if exist "Archive*.tib" (
echo. ren "Archive*.tib" "Backup_%date:~-4,4%_%date:~-10,2%_%date:~-7,2%_%hr%_%time:~3,2%_%time:~6,2%.tib"
)
echo. start "" "C:\DeltaCopy\deltac.exe" localbak.dcp
pause
exit 0
you can't evaluate variables in a code block that get assigned within that ( block ) using %immediate expansion%. Their values are substituted before the ( block ) is executed. Hence the doubling of if exist "Archive*.tib" command.
Other options are call echo.variable=%%variable%%_ and setlocal enableDelayedExpansion &echo.variable=!variable!_
call echo.variable=%%variable%%_ is a trick, the block is read and variables are substituted %% becomes %, then call is used to trigger another substitution %variable% now we get the value assigned inside the block.
With delayedExpansionEnabled you explicitly tell dos a variable is delayed by using ! instead of %.