by Jan Nawara (3 Submissions)
Category: Files/File Controls/Input/Output
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (1 Votes)
A short pathname of the passed string containing a long pathname.
'For example it turns "C:\Windows\MY Long Path Name\My Long Name File.txt" into "c:\windows\mylong~1\mylong~1.txt" (The actual resulting pathname is determined by the short names that windows assigns to all files and directories).
'This is useful when you need to create a fail proof pathname (assuming the file exists and is accesible).
Inputs
Requires that a pathname be passed.
Code Returns
A short DOS 8.3 format pathname.
API DeclarationsDeclare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
Public Function Short_Name(Long_Path As String) As String
'Returns short pathname of the passed long pathname
Dim Short_Path As String
Dim PathLength As Long
Short_Path = Space(250)
PathLength = GetShortPathName(Long_Path, Short_Path, Len(Short_Path))
If PathLength Then
Short_Name = Left$(Short_Path, PathLength)
End If
End Function