Code: Select all
@echo off
cls
setlocal
(
echo c123abc
echo c234abc
echo c345abc
echo cfcd123
)>%temp%\_file.tmp
set mypath=c:\xxx\sys\exe\folder\folder\
echo:
setlocal enabledelayedexpansion
for /f "delims=" %%a in (%temp%\_file.tmp) do (
set "sid=%%a"
rem :: set "sid=!sid:~1,3!"
set mypath=%mypath:xxx=!sid:~1,3!%
echo sid: !sid!, servername: !sid:~1,3!, newpath: !mypath!
)
endlocal
echo Completed.
exit /b 0
that produce this output:
Code: Select all
sid: c123abc, servername: 123, newpath: c:\123\sys\exe\folder\folder\
sid: c234abc, servername: 234, newpath: c:\234\sys\exe\folder\folder\
sid: c345abc, servername: 345, newpath: c:\345\sys\exe\folder\folder\
sid: cfcd123, servername: fcd, newpath: c:\fcd\sys\exe\folder\folder\
Completed.
All that I know about variable expansions (normal and delayed) say me that this line:
Code: Select all
set mypath=%mypath:xxx=!sid:~1,3!%
should fail: the %mypath:whichever% expansion should be done just one time when the FOR was parsed. However, accordingly to the results obtained, is seems that the %mypath:....% expansion is executed each time that the !sid:~1,3! expansion is done, and after it!!!
EDIT: A simple test of my own:
Code: Select all
@echo off
setlocal EnableDelayedExpansion
set "dummy=X"
for /L %%i in (1,1,9) do (
set "array[%%i]=%dummy:X=!random!%
)
set array
What is happening here?
Antonio