Make your own free website on

Convert Long File Names To Short File Names

'Add a module to your project (In the menu choose Project -> Add Module, Then click Open)
'Insert the following code to your module:

Declare Function GetShortPathName Lib "KERNEL32" Alias "GetShortPathNameA" _
(ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal _
cchBuffer As Long) As Long
Public Const PATH_LEN& = 164

'Insert the following code to your form:

Public Function sGetShortFileName(ByVal FileName As String) As String
Dim lRC As Long
Dim sShortPath As String
sShortPath = String$(PATH_LEN + 1, 0)
lRC = GetShortPathName(FileName, sShortPath, PATH_LEN)
sGetShortFileName = Left$(sShortPath, lRC)
End Function

Private Sub Form_Load()
'Replace 'c:\program files' with the path/file you want to find its short name.
'The path must be exist on your computer

MsgBox sGetShortFileName("c:\program files")
End Sub

Go Back