Search Tools Links Login

Convert Long Filename to Short

Posted: 2019-09-30
By: DavidCostelloe
Viewed: 218

Filed Under:

VB6 String Handling, VB6 Files and I/O, VB6 Code Cache

No attachments for this post

Nothing more than converting a long filename to a short 8.3 style filename.


Private Declare Function GetShortPathName Lib "kernel32.dll" Alias "GetShortPathNameA" ( _
    ByVal lpszLongPath As String, _
    ByVal lpszShortPath As String, _
    ByVal cchBuffer As Long_
    ) As Long
Public Function ShortName(LongPath As String) As String
' Converts Long FileName to Short FileName
    Dim ShortPath As String
    Dim Ret As Long
    Const MAX_PATH = 260

    If LongPath = "" Then
        Exit Function
    End If
    ShortPath = Space$(MAX_PATH)
    Ret = GetShortPathName(LongPath, ShortPath, MAX_PATH)
    If Ret Then
        ShortName = Left$(ShortPath, Ret)
    End If
End Function


Private Sub Command1_Click()
    MsgBox ShortName("C:\Program Files\Microsoft Visual Studio\Longexecutable.EXE")
    ' Good for Shell uses or Name etc
End Sub

Special Instructions

This code originally appeared on, and has been republished here with the permission of Andrea Tincani.

Comments on this post

No comments have been added for this post.

You must be logged in to make a comment.