CodeItBetter Programming Another VB Programming Blog

How to Return Short path for given file (with long path)

Posted on January 4, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
'File/Folder Handling - How to Return Short path for given file (with long path)
Option Explicit
 
Private Declare Function GetShortPathNameA Lib "kernel32" (ByVal lpszLongPath As String, _
    ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
 
Public Function GetShortPathName(ByVal sLongPath As String) As String
    Dim s As String
    Dim I As Long
    i = Len(sLongPath) + 1
    s = String(i, 0)
    GetShortPathNameA sLongPath, s, i
    GetShortPathName = Left$(s, InStr(s, Chr$(0)) - 1)
End Function
 
'How can I call this function:
'Debug.Print GetShortPathName("c:\Program Files\")
'Will return c:\PROGRA~1\
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.