Quantcast
Channel: Tech Support Guy
Viewing all articles
Browse latest Browse all 38405

Delayed Expansion is Enabled but Variables are not expanding in FOR loop

$
0
0
Code:

@echo off
SetLocal EnableDelayedExpansion

SET count=1

FOR /f "tokens=*" %%G IN ('dir /b') DO (
        echo %count%:%%G
        set /a count+=1
        )
       
EndLocal

Just a simple example, but the variable stays at 1

Code:

@echo off
setlocal EnableDelayedExpansion
:: count to 5 storing the results in a variable
set _tst=0
FOR /l %%G in (1,1,5) Do (echo [!_tst!] & set /a _tst+=1)
echo Total = !_tst!

This one works... why not the first one? I would much rather use the first method in a much larger script that I am working on...

Thx in advance, GB

Viewing all articles
Browse latest Browse all 38405

Trending Articles