11 Nov 2008

Script - Getting 8.3 (or short) path from a long one

I have this application that need it's paths to be in the old 8.3 (or short) format.  For sometime now, I've been planning to write a script that take a really long filename and convert it to its short equivalent. I am sharing the result with everyone, in case anyone else has the same need.

For those who've never had to use DOS or anything before Windows XP, there was a time when all Microsoft file and folder names were restricted to 8 + 3 characters (see Short Filename convention).
For legacy applications that are still stuck in that era need to have paths that today look like this
"C:\Documents and Settings\Administrator\Application Data\Adobe\Acrobat\9.0\Forms\AdhocWorkflow.doc"

to be changed to look like this

C:\DOCUME~1\Admini~1\APPLIC~1\Adobe\Acrobat\9.0\Forms\ADHOCW~1.DOC

before it can be used. Ughh, I know! Doing this manually becomes painful as the path gets longer.

So I put together this small command-line script named "longtoshort.vbs" written in VBScript to do it for me. The code for this tool is put up here for everyone's benefit. The usage is simple:

longtoshort.vbs [The Long path to be converted]

For Example,

longtoshort.vbs "C:\Documents and Settings\Administrator\Application Data\Adobe\Acrobat\9.0\Forms\AdhocWorkflow.doc"

Note that the long path needs to be enclosed in double quotes to allow for spaces within the path name. Press Enter and the script pops up the short path in a dialogue box for copy-pasting into your application (screen shot below)

image

Now isn't that handy!

Worth Reading Next: How to add this script to the Windows context menu (the one that appears when you right click a file)