title: is this a legit "trick" to get the folder a batch file is executing from?
body: <p>I am debugging a complicated script that "works" correctly (even with errors) on a windows 10 system that has the standard 8dot3name convention but fails when the shortened names do not follow the "standard" (whatever that is)</p>
  
  <p>my test batch file is "runtest.bat" and it is in my "documents\win_build" folder</p>
  
  <pre><code>@echo off
  SET BUILDROOT=%~dps0
  ECHO 1------%BUILDROOT%
  SET BUILDROOT=%BUILDROOT:\win_bu~1\=%
  ECHO 2------%BUILDROOT%
  </code></pre>
  
  <p>the output is</p>
  
  <pre><code>C:\Users\josep\Documents\WIN_BUILD&gt;runtest.bat
  1------C:\Users\josep\DOCUME~1\WIN_BU~1\
  2------C:\Users\josep\DOCUME~1
  </code></pre>
  
  <p>The output needed is that line "2---" which is correct.  Note that there is no trailing backslash which is important***</p>
  
  <p>The problem I have run into is that <code>win_bu~1</code> it not always the shorted name. On my NFS the short name for win_build is actually <code>WOH7UM~G</code> and the build script will fail.</p>
  
  <p>I can get the actual shortened name with</p>
  
  <pre><code>for %%I in (.) do SET SHORT_WIN_BUILD=%%~nsxI
  </code></pre>
  
  <p>The above gives me either win_bu~1 or WOH7UM~G which are correct</p>
  
  <p>Surely there is a better way to get the folder w/o using shortened names.  I am thinking this script was written to be as obtuse as possible.</p>
  
  <p>***  <code>%~dp0</code> gets the current directory but has a trailing backslash which I do not know how to remove and do not wish re-write the script to account for the extra backslash.</p>