How to Convert Long file names to Short file names
Posted on January 5, 2009
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | 'File/Folder Handling - How to Convert Long file names to Short file names Option Explicit '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 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 'How can I use this function: Private Sub Form_Load() 'The path must be exist on your computer MsgBox sGetShortFileName("C:\Program Files\Microsoft Office") End Sub |