There are two methods to setting and using variables within for loops and parentheses scope.
-
setlocal enabledelayedexpansion
seesetlocal /?
for help. This only works on XP/2000 or newer versions of Windows.
then use!variable!
instead of%variable%
inside the loop… -
Create a batch function using batch goto labels
:Label
.Example:
for /F "tokens=*" %%a in ('type %FileName%') do call :Foo %%a goto End :Foo set z=%1 echo %z% echo %1 goto :eof :End
Batch functions are very useful mechanism.