This is giving me little headache.
I fillup an array with ip adresses and hostnames. When filling the array the corresponding element shows added to the array.
Data for sentinels.txt:
127.0.0.1 loopback 192.168.100.102 printer
When populating the array afterwards it is empty??
SET /a HostCount=0
FOR /F "tokens=1,2 delims= " %%A in (Sentinels.txt) DO (
SET ListHosts[%HostCount%]=%%A
ECHO !HostCount! !ListHosts[%HostCount%]!
)
REM Check if array ListHosts is empty
IF not "%ListHosts%"=="" (
FOR /f %%i IN (%ListHosts%) DO (
ECHO %%i
)
)
Thanks in advance, I need the solution to be compatible with an array, a shown in the sample code, the existing questions here are all using a list example.
I have edited the example as good to a multi dimension.
Data for sentinels.txt:
127.0.0.1 loopback 192.168.100.102 printer
SET /A ElapsedCount=1
SET newline=^
SET list=Pi Ho Pa
FOR /F %%i IN ("%list: =!newline!%") DO (ECHO item is %%i in array)
pause
FOR /F %%A IN (Sentinels.txt) DO (
SET /A HostCount+=1
SET _local=127.0.0.1
FOR /F %%i IN ("%list: =!newline!%") DO (
SET array[!HostCount!, !i!, !ElapsedCount!] = !_local! && ECHO !_local! ARR:: !array[ !HostCount!, !i!, !ElapsedCount!]!
SET array[!HostCount!, !i!, !ElapsedCount!] = !_local! && ECHO ARR:: !array[ !HostCount!, !i!, !ElapsedCount!]!
SET array[!HostCount!, !i!, !ElapsedCount!] = !_local! && ECHO ARR:: !array[ !HostCount!, !i!, !ElapsedCount!]!
)
)
I am not sure if the _local variable is correctly written to the array, nor do I get it out of the array.
I got tricked with exclamation/percent delayedexpansion.