[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)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.