borderAndreaVB free resources for Visual Basic developersborder
AndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2018 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
:: Related Topics
icon 13-02-2012 Re: Access 2007 & Win7 by ladyoftheputers
icon 31-01-2010 Re: new version 1.1.0 by freddysam
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
borderAndreaVB free resources for Visual Basic developersborder
borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2018 Andrea Tincaniborder