SETLOCAL ENABLEDELAYEDEXPANSION
will allow what dexter3 is trying.
Quote from "set /?" :
Delayed environment variable expansion allows you to use a different
character (the exclamation mark) to expand environment variables at
execution time. If delayed variable expansion is enabled, the above
examples could be written as follows to work as intended:
set VAR=before
if "%VAR%" == "before" (
set VAR=after
if "!VAR!" == "after" @echo If you see this, it worked
)
replace the % with ! in the right spots above and you're all set, pardon the pun.
2K
(\o/)
Main Topics
Browse All Topics





by: dexter3Posted on 2004-02-23 at 16:35:18ID: 10437160
I thought this question had an easy answer... til I spent the last 90 minutes working on it. The code I'm including below should make clear what I'm trying to do, and also what the issue is. It seems the calculation done by the SET command is actually taking place, but not until AFTER the entire loop is complete, so you can't use the return from the SET command to name your variable (var1, var2, ...). Very strange. Seems to me this code should work... but it doesn't. Might point you in the right direction though.
trings.txt
@echo off
set myfile=c:\temp\experts\mys
set varname=var
set counter=0
rem I'm not sure if you can group the general DO command with parentheses
rem but I know you can within an IF statement, so compare to equals.
for /F "tokens=1,2 delims= " %%i in ('type %myFile% ^| find/i "1000"') do if 1==1 (
set /A counter+=1
echo %counter% %%i
set %varname%%counter%=%%i
)
echo %counter%
pause