Untuk menyingkat nama path, kita membuhtuhkan fungsi API PathCompactPathEx. Berikut merupakan contoh kode untuk menyingkat nama path:
Option ExplicitContoh penggunaan prosedur di atas:
Private Declare Function PathCompactPathEx Lib "shlwapi.dll" Alias "PathCompactPathExA" ByVal pszOut As String, ByVal pszSrc As String, ByVal cchMax As Long, ByVal dwFlags As Long) As Long
'simpan dalam modul
Public Function ShortFilePath(FilePath As String, Optional MaxLen As Long = 40) As String
Dim ShortPath As String
On Error Resume Next
ShortPath = String(255, 0)
PathCompactPathEx ShortPath, FilePath, MaxLen, 0
ShortFilePath = ShortPath
End Function
Private Sub Form_Load()
Text1.Text = ShortFilePath("F:\Project\Outlook Bar control + Photoshop Color Picker v1.3.2\3. Samples\Images")
'akan menghasilkan "F:\Project\Outlook Bar con...\Images"
End Sub