title: How to get information about current path %CD% in batch in a FOR loop?
body: <p>I set an environment variable with several comma separated directory paths and use a <strong>FOR</strong> loop to set current directory to next directory path in variable. And I try to get current path, but it looks strange about result. </p>
  
  <p>I try to use following code:</p>
  
  <pre><code>set a=C:\test\A,C:\test\B,C:\test\C
  
  for %%i in (%a%) do (
      echo %%i
      echo 1 %CD%
      cd %%i
      echo 2 %CD%
      echo ""
  )
  </code></pre>
  
  <p>And result is:</p>
  
  <pre><code> C:\test&gt;TEST.BAT
   C:\test\A
   1 C:\test
   2 C:\test
   ""
   C:\test\B
   1 C:\test
   2 C:\test
   ""
   C:\test\C
   1 C:\test
   2 C:\test
   ""
  
   C:\test\C&gt;
  </code></pre>
  
  <p><code>%CD%</code> should be changed after <code>cd %%i</code>. But all <code>echo %CD%</code> output the batch file path <code>C:\test</code> being the current directory on starting the batch file.</p>
  
  <p>How can I get correct current path?</p>