I'm trying to get a script going that looks for the last in a sequence of directories and creates a new directory one more than the last. And then uses xcopy to copy to the new directory. Finally the script is supposed to delete a trailing directory, but it does not work. There seems to be a problem concatenating the directory string name with the loop counter.
@echo off
set target=d:
set dirname=%target%snapshot
set /a term=3
set /a numsnaps=3
set /a last=0
for /l %%i in (1, 1, %term%) do (
set d=%dirname%%i%
if exist "%d%\" (
echo "found dir %d%"
set /a last=%i%
) else echo "not found dir %d%"
)
if %last% lss %term% (
set /a d=%dirname%%last% + 1
mkdir "%d%"
echo "made dir %d%"
xcopy source "%d%" /e
set /a j=%i% - %numsnaps%
set d=%dirname%%j%
if exist "%d%\" rmdir "%d%"
) else echo Error last snapshot number reached
It outputs:
"found dir "
Missing operand.
...