GetShortPathName Function

GetShortPathName Lib "kernel32.dll" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, lpszShortPath As String, ByVal cchBuffer As Long) As Long

Platforms: Win 32s, Win 95/98, Win NT

GetShortPathName converts a long filename into the old-style 8.3 filenames. Although Windows 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.

lpszLongPath
The complete long path and filename to convert.
lpszShortPath
A string which receives the short filename equivalent.
cchBuffer
The size in characters of lpszShortPath.

Example:

' Find the equivalent short filename "of C:\My Documents\ReadMeFirst.txt"
Dim shortname As String  ' receives short-filename equivalent
Dim slength As Long  ' receives length of short-filename equivalent

shortname = Space(255)  ' make room in the buffer for the short filename
slength = GetShortPathName("C:\My Documents\ReadMeFirst.txt", shortname, 255)
shortname = Left(shortname, slength)  ' extract returned string from buffer
Debug.Print "Equivalent: "; shortname

Related Call: GetFullPathName
Category: Files
Back to the index.


Go to Paul Kuliniewicz's Home Page.
E-mail: rogue953@hotmail.com
This page is at http://skyscraper.fortunecity.com/transmission/45/api/g/getshortpathname.html