Declare Function GetShortPathName Lib "kernel32.dll" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
GetShortPathName converts a long filename into the old-style 8.3 filenames. Although Windows allows the use of long filenames, DOS programs and 16-bit Windows programs must use the 8.3 equivalent. For example, the equivalent of ReallyLongFile.txt could be REALLY~1.TXT.
If successful, the function returns the length of the string copied into lpszShortPath, not including the terminating null character. If an error occured, the function returns 0 (use GetLastError to get the error code).
None.
' This code is licensed according to the terms and conditions listed here.
' Declarations and such needed for the example:
' (Copy them to the (declarations) section of a module.)
Public Declare Function GetShortPathName Lib "kernel32.dll" Alias "GetShortPathNameA" _
(ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer _
As Long) As Long
' Find the short filename equivalent of "C:\My Documents\ReadMeFirst.txt"
Private Sub Command1_Click()
Dim shortname As String ' receives short-filename equivalent
Dim slength As Long ' receives length of short-filename equivalent
' Make room in the buffer to receive the 8.3 form of the filename.
shortname = Space(256)
' Get the 8.3 form of the filename specified.
slength = GetShortPathName("C:\My Documents\ReadMeFirst.txt", shortname, 256)
' Remove the trailing null and display the result.
shortname = Left(shortname, slength)
Debug.Print "Equivalent: "; shortname
End Sub
Go back to the alphabetical Function listing.
Go back to the Reference section index.
Last Modified: July 4, 2000
This page is copyright © 2000 Paul Kuliniewicz.
Copyright Information Revised October 29, 2000
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/g/getshortpathname.html