Search Tools Links Login

Convert Long Filename to Short


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

Module

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

Usage

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

About this post

Posted: 2019-09-30
By: DavidCostelloe
Viewed: 254 times

Categories

Visual Basic 6

Attachments

No attachments for this post

Special Instructions

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


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.