Even in this day and age, rare occasions still exist where we need to access the so-called short path to files. In my case, I was trying to call upon an executable using a script within another program as part of an automation strategy. This required sending an event to the system, which demanded I use the short path to the executable in question.
Short paths follow the old DOS restriction of 8.3 filenames, or 8 characters and a 3 character file extension. Every file, no matter whether it has a long filename in the new style also has a hidden and corresponding short path that shortens file and folder names and deletes spaces, etc.
The trouble is, how to discover it when needed. Often, with experience, you can deduce what it would be. But other times the answer is inscrutable. Take the following, for example. An experienced eye would think that the short path to the Dreamweaver executable would be C:\Progra~2\Adobe\Adobed~2\Dreamw~1.exe, but for some reason it isn't and don't ask me why. Only Windows knows, and there's no arguing. What you need is a foolproof tool to dig into the deranged thinking of the operating system.
The easy way is to download my zipped file here, unzip it onto your desktop or into some other folder, and then use your mouse to drag the file or folder whose short path you need onto it. This simple process will pop up a message with the magic answer highlighted. As you can see, my example above requires a '~3' where I had a '~2', further diminishing my respect for the rules of logic as computers are wont to do on a regular basis, but in this case leaving me at least informed if not enlightened.
My zip file contains a VBS script, and cautious people would never just run a VBS script downloaded from the web. If you are of that sort, you can either examine the code in it before running it (open it in Notepad), or make your own file. To do so, copy and paste the following code into a text editor such as Notepad, and save it with a file name of your choice and a .vbs extension (not .txt).
' Is object a file or folder?
If fso.FolderExists(WScript.Arguments(0)) Then
'It's a folder
Set objFolder = fso.GetFolder(WScript.Arguments(0))
rtrn = InputBox("Here's your short path:", "SHORT PATH", objFolder.ShortPath)
If fso.FileExists(WScript.Arguments(0)) Then
'It's a file
Set objFile = fso.GetFile(WScript.Arguments(0))
rtrn = InputBox("Here's your short path:", "SHORT PATH", objFile.ShortPath)
That should do it. If you wish, you can place the file or a shortcut to it in your 'Send To' folder so that you can right-click on a file or folder at any time and conveniently send it to the VBS script. In Windows 7, the Send To folder is normally located at: C:\Users\YourName\AppData\Roaming\Microsoft\Windows\SendTo
Happy discoveries, and my thanks to flajason-ga for a great solution that I was able to track down on this page.