65.9K
CodeProject is changing. Read more.
Home

Get DOS 8.3 short name with VbScript

emptyStarIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

0/5 (0 vote)

Nov 23, 2009

CPOL
viewsIcon

24162

Create a new text file called shortname.vbs:Open in Notepad and paste the following code in it:set fso = CreateObject("Scripting.FileSystemObject") strLongName = Wscript.Arguments(0)strShortName = "Invalid File/Folder - (" & strLongName & ")"Set fsoFile = NothingOn Error Resume...

Create a new text file called shortname.vbs: Open in Notepad and paste the following code in it:
set fso = CreateObject("Scripting.FileSystemObject") 

strLongName = Wscript.Arguments(0)
strShortName = "Invalid File/Folder - (" & strLongName & ")"
Set fsoFile = Nothing

On Error Resume Next

Set fsoFile = fso.GetFile(strLongName)

if Err.number <> 0 then
	Set fsoFile = fso.GetFolder(strLongName)
end if

if fsoFile is not nothing then
	strShortName = fsoFile.ShortPath
end if
Wscript.Echo strShortName
Run the script using cscript:
cscript shortname.vbs "C:\Program Files\Adobe\Reader 9.0\Reader\AcroRd32.exe"
You will then get the following output:
C:\PROGRA~1\Adobe\READER~1.0\Reader\AcroRd32.exe