title: split path and take last folder name in batch script
body: <p>I want to split the string (having a path) with <code>\</code>and take last folder name in a variable. Please help.</p>
  
  <p>e.g<br>
  mypath=D:\FOLDER1\FOLDER2\FOLDER3\</p>
  
  <p>I want FOLDER3 in a variable.</p>
  
  <p>I tried with the command below which is working if the the last character is not <code>\</code> :  </p>
  
  <pre><code>for %f in (C:\FOLDER1\FOLDER2\FOLDER3) do set myfolder=%~nxf
  </code></pre>
  
  <p>It is not working if the last character is <code>\</code></p>
  
  <p>Also it is not working if variable is used like :
  <strong>for %f in (%mypath%) do set myfolder=%~nxf</strong></p>