AllAPI Network - The KPD-Team

Allapi Network

 API List

API Resources
 Tips & Tricks
 VB Tutorials
 Error Lookup
Misc Stuff
 VB examples
 VB Tools
 VB Links
 Top Downloads
This Site
 Search Engine
 Contact Form

Donate to

Retrieving the Short Path Name

This tip demonstrates how to retrieve to Short Path name for a file.   For instance "c:\my documents\this is a long file.doc" becomes "c:\mydocu~1\thisis~1.doc".   This tip used the GetShortPathName API function that is built into a Windows DLL.


Copy this code into the declarations section of your project.

Declare Function GetShortPathName Lib "kernel32" Alias _
"GetShortPathNameA" (ByVal lpszLongPath As String, ByVal _
lpszShortPath As String, ByVal lBuffer As Long) As Long            


Copy this function into your project.

Public Function GetShortPath(strFileName As String) _
As String

Dim lngRes As Long
Dim strPath As String

strPath = String$(165, 0)
lngRes = GetShortPathName(strFileName, strPath, 164)
GetShortPath = Left$(strPath, lngRes)

End Function


An example of use:

Dim StrShortPath as String
StrShortPath = GetShortPath("c:\dir\this is long.doc")            

StrShortPath is now set to "c:\dir\thisis~1.doc"



Copyright © 1998-2007, The Team - Privacy statement
Did you find a bug on this page? Tell us!
This site is located at