This tip
demonstrates how to retrieve to Short
Path name for a file. For instance
"c:\my
documents\this is a long file.doc"
becomes "c:\mydocu~1\thisis~1.doc".
This tip used the GetShortPathName API
function that is built into a Windows
DLL.
Declarations
Copy this code into
the declarations section of your project.
Declare Function GetShortPathName Lib
"kernel32" Alias _
"GetShortPathNameA" (ByVal lpszLongPath As
String, ByVal _
lpszShortPath As String, ByVal lBuffer As Long) As
Long
Code
Copy this function
into your project.
Public Function
GetShortPath(strFileName As String) _
As String
Dim lngRes As Long
Dim strPath As String
strPath = String$(165, 0)
lngRes = GetShortPathName(strFileName, strPath, 164)
GetShortPath = Left$(strPath, lngRes)
End Function
Use
An
example of use:
Dim StrShortPath as String
StrShortPath = GetShortPath("c:\dir\this is
long.doc")
StrShortPath
is now set to
"c:\dir\thisis~1.doc"
|