title: Batch file: Accessing array elements in for loop
body: <p>I am confused at how to access array values from inside a for loop in a windows batch file.  Here is my test:</p>
  
  <pre><code>@ echo off
  SET ROOT=c:\temp\test
  
  REM set up array of local dir paths
  SET LDIR[1]=data
  SET LDIR[2]=data\fonts
  SET LDIR[3]=data\images
  
  for /L %%s in (1,1,3) do (
    IF EXIST %ROOT%\%%LDIR[%%s]%% (
      call echo %ROOT%\%%LDIR[%%s]%% exists
    ) else (
      call echo %ROOT%\%%LDIR[%%s]%% does not exist
    )
  )
  </code></pre>
  
  <p>I get output:</p>
  
  <pre><code>c:\temp\test\data does not exist
  c:\temp\test\data\fonts does not exist
  c:\temp\test\data\images does not exist
  </code></pre>
  
  <p>even though the dirs exist.  I believe the array is not getting derefernced correctly in the IF EXISTS statement. What is the correct way to do this?  Also Why is it necessary to use "call" to get the array to dereference correctly?
  --Thanks!</p>