title: Batch file: How to get variable's value using variable's name already stored in a string
body: <p>1)  Quick example:</p>
  
  <pre><code>set a="Hello"
  set d="a"
  </code></pre>
  
  <p>Now, how do I get the value of "a" using (the value of) variable <code>d</code>?  For example, the variable name could have been entered by a user using a prompt, or the name of the variable could have been sent to a function.</p>
  
  <p>None of these ideas work:</p>
  
  <pre><code>set e=%%d%%
  
  set e=%%%d%%%
  
  set e=set e=%%d%%
  %e%
  </code></pre>
  
  <p>After an hour of brainstorming and Googling, I have come up with this, but it seems too complicated and clumsy - is there really no other/easier way?:</p>
  
  <pre><code>set a="Hello"
  set b="Good day"
  set c="Good night"
  
  set /p d="Give me a variable name"
  
  call :GetVarVal %%%d%%% "e"
  
  REM This now gives the correct value:
  echo %e%
  
  goto :eof
  
  :GetVarVal
    set "%~2=%~1"
  goto :eof
  </code></pre>
  
  <p>2)  Also, sort of similar, is there a better way to do this (ideally without a custom function):</p>
  
  <pre><code>set a="C:\Users\Blah\Documents\MP4Box\MP4Box.exe"
  
  call :get_drive_and_path a
  
  echo %b%
  
  goto :eof
  
  :get_drive_and_path
    set b=%~dp1
  goto :eof
  </code></pre>
  
  <p>Thanks!</p>