|
|
Getting the 8.3 file Name associated With a Long File NameQuestionI'm attempting to shell off to another application and the other app doesn't support long file names. Is there a way to obtain the associated 8.3 file name programmatically? Answer
Private Declare Function smsGetShortPathName& _
Lib "Kernel32" Alias "GetShortPathNameA" _
(ByVal lpszLongPath As String, _
ByVal lpszShortPath As String, _
ByVal cchBuffer As Long)
Public Function ShortPathNameGet(ByVal vstrLongPath As String) As String
'
' written by Shamil Salakhetdinov: shamil@marta.darts.spb.ru
'
Dim strTmpBuf As String * 512
Dim lngTmpBufLen As Long
Dim lngRet As Long
lngTmpBufLen = 512
lngRet = smsGetShortPathName(vstrLongPath, strTmpBuf, lngTmpBufLen)
If lngRet = 0 Then
Err.Raise 503 + vbObjectError, "ShortPathNameGet", _
"File not found: " & vstrLongPath
ElseIf lngTmpBufLen < lngRet Then
Err.Raise 503 + vbObjectError, "ShortPathNameGet", _
"File path greater than temp buffer: " & _
lngRet & " > " & lngTmpBufLen
End If
ShortPathNameGet = Left(strTmpBuf, lngRet)
End Function
Copyright © 1999-2008 by Shamil Salakhetdinov. Original version is published here All rights reserved. |