Get DOS path instead of Windows path

Solution 1:

for %I in (.) do echo %~sI

Any simpler way?

Solution 2:

You could also enter the following into a CMD window:

dir <ParentDirectory> /X

Where <ParentDirectory> is replaced with the full path of the directory containing the item you would like the name for.

While the output is not a simple as Timbo's answer, it will list all the items in the specified directory with the actual name and (if different) the short name.

If you do use for %I in (.) do echo %~sI you can replace the . with the full path of the file/folder to get the short name of that file/folder (otherwise the short name of the current folder is returned).

Tested on Windows 7 x64.

Solution 3:

In windows batch scripts, %~s1 expands path parameters to short names. Create this batch file:

@ECHO OFF
echo %~s1

I called mine shortNamePath.cmd and call it like this:

c:\>shortNamePath "c:\Program Files (x86)\Android\android-sdk"
c:\PROGRA~2\Android\ANDROI~1

Edit: here's a version that uses the current directory if no parameter was supplied:

@ECHO OFF
if '%1'=='' (%0 .) else echo %~s1

Called without parameters:

C:\Program Files (x86)\Android\android-sdk>shortNamePath
C:\PROGRA~2\Android\ANDROI~1