You are not logged in.
hi all
At the begining i want to say that I'm new to the cmd scripts.
I have a problem with a variable inside a for loop. I'm reading data from a file:
season=spring summer autumn winter
month=january february march april may
This is a script code (it's only a test script):
@echo off
FOR /F "eol=# tokens=1,2 delims==" %%i in (%1) do (
if %%i == season SET SEASON=%%j
)
FOR /F "eol=# tokens=1,2 delims==" %%i in (%1) do (
if %%i == month SET MONTH=%%j
)
for %%i in ( %SEASON% ) DO (
for %%j in ( %MONTH% ) do (
set x=%%i\%%j
REM echo %%i\%%j
echo %x%
)
)
The problem is that the x variable has at every iterance the same value:
winter\may
winter\may
winter\may
winter\may
winter\may
winter\may
winter\may
winter\may
winter\may
winter\may
winter\may
winter\may
winter\may
winter\may
winter\may
winter\may
winter\may
winter\may
winter\may
winter\may
While the commented echo %%i\%%j gives the correct result:
spring\january
spring\february
spring\march
spring\april
spring\may
summer\january
summer\february
summer\march
summer\april
summer\may
autumn\january
autumn\february
autumn\march
autumn\april
autumn\may
winter\january
winter\february
winter\march
winter\april
winter\may
Does anyone knows what is the problem?
blah01
Offline
You need to SETLOCAL EnableDelayedExpansion
see the SETLOCAL page
http://ss64.com/nt/setlocal.html
Offline
thx this has solved my problem
Offline