Public Declare Function GetLongPathName Lib "kernel32" _
Alias "GetLongPathNameA" (ByVal lpszShortPath As String, _ ByVal lpszLongPath As String, ByVal cchBuffer As Long) _ As Long Public Declare Function GetShortPathName Lib "kernel32" _ Alias "GetShortPathNameA" (ByVal lpszLongPath As String, _ ByVal lpszShortPath As String, ByVal cchBuffer As Long) _ As Long Public Function GetLongFilename(ByVal sShortFilename As String) _ As String 'Returns the Long Filename associated with sShortFilename Dim lRet As Long Dim sLongFilename As String 'First attempt using 1024 character buffer. sLongFilename = String$(1024, " ") lRet = GetLongPathName(sShortFilename, sLongFilename, _ Len(sLongFilename)) 'If buffer is too small lRet contains buffer size needed. If lRet > Len(sLongFilename) Then 'Increase buffer size... sLongFilename = String$(lRet + 1, " ") 'and try again. lRet = GetLongPathName(sShortFilename, sLongFilename, _ Len(sLongFilename)) End If 'lRet contains the number of characters returned. If lRet > 0 Then GetLongFilename = Left$(sLongFilename, lRet) End If End Function Public Function GetShortFilename(ByVal sLongFilename As String) _ As String 'Returns the Short Filename associated with sLongFilename Dim lRet As Long Dim sShortFilename As String 'First attempt using 1024 character buffer. sShortFilename = String$(1024, " ") lRet = GetShortPathName(sLongFilename, sShortFilename, _ Len(sShortFilename)) 'If buffer is too small lRet contains buffer size needed. If lRet > Len(sShortFilename) Then 'Increase buffer size... sShortFilename = String$(lRet + 1, " ") 'and try again. lRet = GetShortPathName(sLongFilename, sShortFilename, _ Len(sShortFilename)) End If 'lRet contains the number of characters returned. If lRet > 0 Then GetShortFilename = Left$(sShortFilename, lRet) End If End Function |