John Topley's Knowledgebase

Returning The Short Name For A File Path

Friday, 30 May 2003

This Visual Basic code returns the short (MS-DOS) name for a file path.

Download 0022.txt

Private Declare Function GetShortPathName Lib "kernel32" Alias _
   "GetShortPathNameA" (ByVal lpszLongPath As String, _
   ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long

Function GetDosPath(ByVal vStrPath As String) As String
   Dim lngRetVal As Long
   Dim lngBuffer As Long
   Dim strShortPath As String

   ' Pad the destination buffer with zeros, to the length of the input path.
   strShortPath = String$(Len(vStrPath), 0)

   ' Set the size of the buffer pointed to by strShortPath.
   lngBuffer = Len(strShortPath)
   lngRetVal = GetShortPathName(vStrPath, strShortPath, lngBuffer)

   ' Strip the trailing null terminator.
   GetDosPath = Left$(strShortPath, lngRetVal)
End Function

top | index | previous | next | comments ()

home | archive | kb | media | about | contact | accessibility
Copyright © 2003 - 2005 John Topley. Made with CityDesk.