I have attached an image which should illustrate the issue. Basically the script (bottom), when run, should Make two copies of a file determined by the "iter" and "count" variables, copy them to the same folder, and rename them according to the existing sequence.
As one can see the TEST folder (right) displays the correct output up until the "iter" reaches "10". The second nested IF statement in the FOR loop is never executed.
I quickly wrote this WORKING batch to test multiple if conditions:
@echo off
set var=101
if %var% lss 10 (
echo var is less than 10
)
if %var% geq 10 if %var% leq 99 (
echo var is between 9 and 100
)
if %var% gtr 99 if %var% leq 200 (
echo var is between 99 and 200
) else (
echo %var% is beyond bounds
)
pause
So why then is my script below not working as it should?
@echo off
setlocal enabledelayedexpansion
set iter=1
set count=1
for %%i in (C:\TEST\*.txt) do (
set name=%%~dpni
pause
if %count%==%iter% (
if !iter! lss 9 (
set /a count+=1
copy "%%i" "!name:~0,-1!!count!%%~xi"
set /a count+=1
copy "%%i" "!name:~0,-1!!count!%%~xi"
set /a count+=1
)
if !iter! gtr 9 if !iter! lss 100 (
set /a count+=1
echo "!name:~0,-2!!count!%%~xi"
pause
copy "%%i" "!name:~0,-2!!count!%%~xi"
set /a count+=1
copy "%%i" "!name:~0,-2!!count!%%~xi"
set /a count+=1
)
) else (
set /a iter+=1
)
)
pause
- Edited by CMJR1979 Sunday, March 29, 2015 5:53 PM