Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I get the DOS short path name of a file

Folders and Files

How do I get the DOS short path name of a file

by  swilliams  Posted    (Edited  )
Use an API call:

[color blue]Add a module to your project and insert the following code in the module:[/color]

Option Explicit

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

Public Function GetShortName(ByVal sLongFileName As String) As String

Dim lRetVal As Long, sShortPathName As String, iLen As Integer
'Set up buffer area for API function call return
sShortPathName = Space(255)
iLen = Len(sShortPathName)

'Call the function
lRetVal = GetShortPathName(sLongFileName, sShortPathName, iLen)
'Strip away unwanted characters.
GetShortName = Left(sShortPathName, lRetVal)

End Function


Then, to get the DOS short name of a file, call the function GetShortName like this:

Dim sFileName As String
Dim sShortName As String

sFileName = "C:\Documents and Settings\Administrator\My Documents\My Pictures\longpicturename.jpeg"

' call the function
sShortName = GetShortName(sFileName)
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top