title: Get the parent folder name of the currently executing batch script
body: <p>A batch file on Windows (XP and later) needs to know the name of the directory it's located in. Only the folder name, not the whole path and not the batch file name itself.</p>
  
  <p>So the file stored in C:\temp\abc\script.cmd should get the name "abc" in a variable.</p>
  
  <p>How can that be done?</p>
  
  <p>The usual parameter extensions like <code>%~p0</code> can only extract the entire path (\temp\abc\ ) and they only work on real parameters (%0, %1, %2...) not on other variables, so they cannot be stacked or combined. So they're too limited for this task. The <code>for</code> command can only address tokens at a defined position from the start, not the "last" or second-last token.</p>
  
  <p>For simplicity of execution and portability, it must be a batch file (.cmd), not PowerShell.</p>