GetShortPathName Lib "kernel32.dll" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, lpszShortPath As String, ByVal cchBuffer As Long) As Long
GetShortPathName converts a long filename into the old-style 8.3 filenames. Although Windows 95 allows the use of long filenames, DOS programs, not to mention 16-bit Windows programs, must use the 8.3 equivalent. For example, the equivalent of ReallyLongFile.txt could be REALLY~1.TXT. The short filename is put into the string variable passed as lpShortPath. The function returns the length of the string, or 0 if the function failed.
Example:
' Convert C:\My Documents\RichTextOne.rtf to its short equivalent
Dim buffer As String * 255
x = GetShortPathName("C:\My Documents\RichTextOne.rtf", buffer, 255)
Debug.Print Left(buffer, x) ' could be C:\MYDOCU~1\RICHTE~1.RTF
Related Call: GetFullPathName
Category: Files
Back to the index.