I am trying to make a CMD batch script that constantly logs IP statistics and puts them in different .txt files, for this I have created 2 arrays, one that contains the names I wish to give to the txt files and other one that contains the ips I wish to ping.
I try to loop the elements in the arrays as names/parameters for different commands on the CMD shell, the part for the .txt names works but I can't get extracting the ip addresses from the corresponding array and passing them to the ping command to work. My code is:
@echo off
set Noms=(bni csc cba lpz oro pnd pts scz trj)
set Dirs=(8.8.8.8 8.8.8.4 8.8.8.4 8.8.8.8 8.8.8.8 8.8.8.4 8.8.8.8 8.8.8.4 8.8.8.8)
rem --------------------------------------------------------------
rem Builds .txts with names in list Noms pinging Addresses in Dirs
rem --------------------------------------------------------------
for %%j in %Noms% do (
set direccion = %Dirs[%%j]%
ping /n 3 %direccion% > c:\log\p0.txt
findstr "Media" c:\log\p0.txt > c:\log\p1.txt
for /f "tokens=3 delims=," %%i in (c:\log\p1.txt) do @echo %%i > c:\log\p2.txt
for /f "tokens=4 delims=<equal> " %%i in (c:\log\p2.txt) do @echo %%i > c:\log\p0.txt
for /f "tokens=1 delims=m" %%i in (c:\log\p0.txt) do (set pingvar=%%i)
for /f "tokens=1-3 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%a-%%b) 
For /f "tokens=1-3 delims=/:," %%a in ("%TIME%") do (set mytime=%%a:%%b:%%c) 
set totvar=%mydate%     %mytime%    %pingvar%
echo %totvar% > c:\log\%%j.txt
)
I found no mistake in my code, basically I try to put the IP address from the array "Dirs" in the variable "direccion" and then passit as an argument to ping.
Thank you for helping me.

%Dirs[...]%doesn't exist.set "Dirs[bni]=8.8.8.8", ...,set "Dirs[trj]=8.8.8.8"