1.

Solve : Batch script for/if not looping?

Answer»

Win XP SP.3

Why does the For loop in the FOLLOWING script not loop please?

Code: [SELECT]@ECHO off
setlocal enabledelayedexpansion
cls

set year=9
set month=8
set DAY=25
set cnt=1

for /f "tokens=%cnt%" %%1 in ("year month day") do (
if !%%1! lss 10 set %%1=0!%%1!
set /a cnt+=1
)
echo !year!:!month!:!day!
exit /b
Because there is only one line being fed into the for loop. It does the action(s) for each line it is fed.See the lines in red

@echo off
setlocal enabledelayedexpansion
cls

set year=9
set month=8
set day=25
set cnt=1

:loop
for /f "tokens=%cnt%" %%1 in ("year month day") do (
if !%%1! lss 10 set %%1=0!%%1!
set /a cnt+=1
)
if %cnt% LSS 4 goto loop
echo !year!:!month!:!day!






Thank you both.

V.



Discussion

No Comment Found