In a DOS window, how can I get the full DOS name/short name of the directory I am in?
For example, if I am in the directory C:\Program Files\Java\jdk1.6.0_22
, I want to display it's short name C:\PROGRA~1\Java\JDK16~1.0_2
.
I know running dir /x
will give me the short names of files/directories in the current directory but I haven't been able to find a way to display the full path of the current directory in short name format. I'm having to work my way through the path from the root, directory by directory, running dir /x
in each.
I'm sure there is an easier way to do this?
Being a programmer made this 10-minute Winform project. It's been useful for me. Making this app to a context menu for file explorer would save more clicks.
Form1.cs:
Form1.Designer.cs:
similar to this answer but uses a sub-routine
Kimbo's answer is perfect for normal files.
For MsDos file names on HardLinks
The hard links created with
mklink /H <link> <target>
will not have an MsDos short file name.In case you
dir /X
and you discover that missing short name you should expect the followings:Normal file
In this case
I've got what I expected
Hard link file
In this case
I've got the normal MsDos path but the normal filename.
Any simpler way?
In windows batch scripts,
%~s1
expands path parameters to short names. Create this batch file:I called mine
shortNamePath.cmd
and call it like this:Edit: here's a version that uses the current directory if no parameter was supplied:
Called without parameters:
You could also enter the following into a CMD window:
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.