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\

Related posts:

  1. How to retrieve the full long path name from short path (MS Dos format)
  2. How to Convert Long file names to Short file names
  3. How to Return the path of a given full path to a file
  4. How to Return the filename of a given full path to a file
  5. How to get the file path for the selected file using Common Dialog control
  6. How to Return the Path portion of a file (in two ways)
  7. How to get file name alone from a file name with its full path
  8. How to return the path to the windows directory.
  9. How to return the path to the system directory.
  10. How to get the file name without its extension and path

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.