
Api function to convert Long File Names To Short Dos File Names
Dear Brian,
here is a piece of code I wrote some time ago, please feel free to use it
Syntax: <shortfilename> = MakeDOSName(<longfilename>)
Private Const MAX_PATH As Integer = 260
Private Declare Function GetShortPathName Lib "kernel32" Alias
"GetShortPathNameA" _
(ByVal lpszLongPath As String, _
ByVal lpszShortPath As String, _
ByVal cchBuffer As Long) As Long
Private Function MakeDOSName(ByVal szLongFileName As String) As String
Dim lAPIResult As Long
' Initialize string w/empty spaces
MakeDOSName = Space$(MAX_PATH)
' Call WinAPI
lAPIResult = GetShortPathName(szLongFileName, _
MakeDOSName, _
Len(MakeDOSName))
If (lAPIResult) Then
' we need to strip the string delimiter
MakeDOSName = Mid$(MakeDOSName, 1, lAPIResult)
End If
' All set
MakeDOSName = Trim$(MakeDOSName)
End Function
Hope this helps,
Luca G. Fontanarosa
Sr. Software Engineer