AndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2006 Andrea Tincani
:: How to Convert Long File Name to Short File Name

Author  

David Costelloe

Language  

VB5, VB6

Operating Systems  

Windows 95, 98 and NT
API Declarations

' API Declare
Private Declare Function GetShortPathName Lib "kernel32.dll" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long

Module

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

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

:: Navigation

Home

Files and Disks Tips

Previous Tip

Next Tip

:: Search this site
Google
Web andreavb.com
:: Related Topics
icon 25-02-2006 Re: please tell me why my customer form gets hung up by kabba
icon 20-09-2005 Converting a font into a graphic image by Racer-X
icon 23-02-2005 Re: Using Access 2000 files with VB6 by yronium
icon 13-01-2005 Re: Errors with text files by yronium
icon 02-11-2004 import in VB some forms from Access by yronium

AndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2006 Andrea Tincani