title: Use a for loop variable to call a predefined variable
body: <p>I'm looking to use a variable which gets defined inside a for loop and use it to call a predefined variable. </p>
  
  <p>For example: To start the program <code>"Slack"</code> I need to call the variable <code>%Slack%</code>.
  The batch file will take your input, so If I input <code>"Slack"</code>, the variable <code>!filename[%%i]!</code> will be assigned <code>"Slack"</code>. Once that is done, I wish to call <code>%Slack%</code> using <code>!filename[%%i]!</code>. As per logic: <code>%!filename[%%i]!%</code></p>
  
  <p>Using <code>%!filename[%%i]!%</code> will make the batch file crash and close. </p>
  
  <p>Setting <code>set file=!filename[%%i]!</code> and running it with <code>%file%</code> will return nothing.</p>
  
  <p>Any smart trick?</p>
  
  <pre><code>@echo off
  
  setlocal EnableDelayedExpansion
  
  :: Predefined variables
  for /f "delims== tokens=1,2" %%G in (D:\programs.txt) do set %%G=%%H
  
  set /P "filenames=Enter programs to install: "
  
  :: Puts input into array
  set n=0
  for %%a in (%filenames%) do (
      set /A n+=1
      set "filename[!n!]=%%~a"
  )
  
  :: Run variables imported from programs.txt
  for /L %%i in (1,1,%n%) do (
  
      :: This is where I want !filename[%%i]! to be called as %!filename[%%i]!%
  
  )
  
  pause
  endlocal
  </code></pre>
  
  <p>program.txt example</p>
  
  <pre><code>Slack=C:\Users\username\AppData\Local\slack\slack.exe
  Text=C:\textfile.txt
  Program=C:\program.bat &amp; C:\program_license.txt
  </code></pre>