Article ID: 154822
Article Last Modified on 7/1/2004
Public Function GetLongFilename _
(ByVal sShortName As String) _
As String
Dim sLongName As String
Dim sTemp As String
Dim iSlashPos As Integer
'Add \ to short name to prevent Instr from failing
sShortName = sShortName & "\"
'Start from 4 to ignore the "[Drive Letter]:\" characters
iSlashPos = InStr(4, sShortName, "\")
'Pull out each string between \ character for conversion
While iSlashPos
sTemp = Dir(Left$(sShortName, iSlashPos - 1), _
vbNormal + vbHidden + vbSystem + vbDirectory)
If sTemp = "" Then
'Error 52 - Bad File Name or Number
GetLongFilename = ""
Exit Function
End If
sLongName = sLongName & "\" & sTemp
iSlashPos = InStr(iSlashPos + 1, sShortName, "\")
Wend
'Prefix with the drive letter
GetLongFilename = Left$(sShortName, 2) & sLongName
End Function
Private Sub Command1_Click()
'Assumes C:\Program Files\Common Files is a valid path
Print GetLongFilename("C:\PROGRA~1\COMMON~1")
End Sub
Additional query words: kbVBp400 vkbVBp500bug kbVBp600bug kbVBp kbdsd kbDSupport KBWIN32SDK KBAPI
Keywords: kbhowto KB154822