but if command1-n depend on the value of variablen, it doesn't work.
cause when it runs to commandn, it still use the oldvalue. how to
write this for loop ?
@echo off
setlocal EnableDelayedExpansion
set variable=oldvalue
for ... in (....) do (
set variable=newvalue
command1 !variable!
command2 !variable!
...
commandn !variable!)
set variable=oldvalue
SETLOCAL /? and SET /? Read about delayed expansion.
However, I don't think I understand what you mean by 'variablen' and
'commandn'. Your construct creates only one variable with changing
contents. However as shown the variable's content is the same for all
commands for each iteration through the loop.
You're just going to have to explain what you are trying to accomplish
in more detail. I don't understand what it is you are trying to do.
Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/
Have a look at the reply I gave you on about 30 April. It looked
likes so:
1. @echo off
2. setlocal enabledelayedexpansion
3. set Source=d:\temp\test.txt
4.
5. for /F "tokens=2,4 delims==" %%a in ('type "%Source%"') do (
6. set projectname=%%a & set projecttype=%%b
7. echo Project name=!projectname! Project type=!projecttype!
8. )
Now have a closer look at Line 2, and also at the exclamation
marks in Line 7. That's your answer!
setlocal enabledelayedexpansion
for ...in ('findstr ....') do (
set projecttype=%%i
set projectname=%%j
if (!projecttype!)=="xxx" echo mycommand > logdir\!projectname!.log
<----works ok!
findstr /i /s /c:Error(s) logdir\!projectname!.log <-----------doesn't
work
)
endlocal
why this happens?
finally i find i should add double quote around the search string :)