Get Short Path


‘add 1 command button, 2 TextBoxes and 1 Module

Option Explicit

Private Sub Command1_Click()

‘variable to hold input path
Dim DosPathName As String

DosPathName = GetDosPath(Text1.Text)
Text2.Text = DosPathName
End Sub

Private Sub Text2_Change()

End Sub

‘Module

Option Explicit

Declare Function GetShortPathName Lib “kernel32” Alias _
“GetShortPathNameA” (ByVal lpszLongPath As String, _
ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long

Public Function GetDosPath(LongPath As String) As String

Dim s As String
Dim i As Long
Dim PathLength As Long

i = Len(LongPath) + 1

s = String(i, 0)

PathLength = GetShortPathName(LongPath, s, i)

GetDosPath = Left$(s, PathLength)

End Function

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s