This batch code should work although it is unclear what you really want:
@echo off
setlocal EnableExtensions EnableDelayedExpansion
rem ...
set "LocaleL1=Example1.exe"
set "LocaleL1.Byte=1234"
rem ...
set "ServerL1=Example2.exe"
set "ServerL1.Byte=4321"
rem ...
set "ServerList.Count=1"
for /L %%A in (1,1,%ServerList.Count%) do (
set "MyLocaleLabel=!LocaleL%%A!"
set "MyServerLabel=!ServerL%%A!"
set "MyLocaleByte=!LocaleL%%A.Byte!"
set "MyServerByte=!ServerL%%A.Byte!"
set My
echo/
)
endlocal
Windows command interpreter first replaces %%A
during loop execution of the command block by current loop variable value. Then SET is executed with delayed environment variable expansion resulting in assigning the value of the environment variable LocaleL1
to environment variable MyLocaleLabel
, value of ServerL1
to MyServerLabel
, value of LocaleL1.Byte
to MyLocaleByte
, and value of ServerL1.Byte
to MyServerByte
.
The values of the four environment variables starting with My
in name are output next. So the posted batch file outputs on running it from within a command prompt window:
MyLocaleByte=1234
MyLocaleLabel=Example1.exe
MyServerByte=4321
MyServerLabel=Example2.exe
I changed all the environment variable names because the original names in question are too confusing for me.
Hint: Do not use an arithmetic expression to assign a value to an environment variable. Environment variables are always of type string.
On using an arithmetic expression with set /a LocalL1.Byte=1234
Windows command interpreter has first to convert the string with the hexadecimal bytes 31 32 33 34 00
to a 32-bit signed integer with value 1234
, hold in memory with the four hexadecimal bytes D2 04 00 00
(LSB to MSB), and next convert the integer back to a string with the five bytes 31 32 33 34 00
. That does not make much sense although done so fast that nobody will ever notice a difference to set "LocalL1.Byte=1234"
in execution time on which just a simple string copy is executed (if at all).
Further run set /?
in a command prompt window and read the output help carefully from first to last page for command SET. Environment variables can and should be in general referenced within an arithmetic expression by just their names without usage of %
or !
, i.e. set /A TCount=TCount + 1
or even shorter set /A TCount+=1
. The help explains why this works in an arithmetic expression any why this syntax is better.
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
echo /?
endlocal /?
for /?
set /?
setlocal /?
And I suggest to read also