AllAPI Network - The KPD-Team

 
Allapi Network
 API-Guide
 ApiViewer

 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 AllAPI.net

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.

Declarations

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            

Code

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

Use

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 Mentalis.org Team - Privacy statement
Did you find a bug on this page? Tell us!
This site is located at http://allapi.mentalis.org/