Article ID: 175512
Article Last Modified on 3/11/2005
Declare Function GetShortPathName Lib "kernel32" _
Alias "GetShortPathNameA" (ByVal lpszLongPath As String, _
ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
Public Function GetShortName(ByVal sLongFileName As String) As String
Dim lRetVal As Long, sShortPathName As String, iLen As Integer
'Set up buffer area for API function call return
sShortPathName = Space(255)
iLen = Len(sShortPathName)
'Call the function
lRetVal = GetShortPathName(sLongFileName, sShortPathName, iLen)
'Strip away unwanted characters.
GetShortName = Left(sShortPathName, lRetVal)
End Function
Private Sub Command1_Click()
Dim msg As String
CommonDialog1.FileName = "*.*"
CommonDialog1.ShowOpen
msg = "Long File Name: " & CommonDialog1.filename & vbCrLf
msg = msg & "Short File Name: " & GetShortName(CommonDialog1.filename)
MsgBox msg
End Sub
154822 How To Get a Long Filename from a Short Filename
Keywords: kbhowto kbdocfix KB175512