Private Sub Command1_Click()
Dim FSys As New Scripting.FileSystemObject
Dim entries As Variant
Dim dir_name As String
Dim i As Integer
On Error Resume Next
CommonDialog1.ShowOpen
If Err.Number = cdlCancel Then
Exit Sub
ElseIf Err.Number <> 0 Then
MsgBox "Error " & Format$(Err.Number) & _
" selecting files." & vbCrLf & Err.Description
Exit Sub
End If
List1.Clear
'entries = Split(CommonDialog1.FileName, vbNullChar)
entries = Split(CommonDialog1.filename, vbNullChar)
' See if there is more than one file.
If UBound(entries, 1) = LBound(entries, 1) Then
' There is only one file name.
List1.AddItem entries(LBound(entries, 1))
Else
' Get the directory name.
dir_name = entries(LBound(entries, 1))
If Right$(dir_name, 1) <> "\" Then dir_name = dir_name & "\"
' Get the file names.
For i = LBound(entries, 1) + 1 To UBound(entries, 1)
List1.AddItem dir_name & entries(i)
Next i
End If
If List1.ListCount = 0 Then GoTo ext
For X = 0 To (List1.ListCount - 1)
List1.ListIndex = X
Next
FSys.GetAbsolutePathName (List1.Text)
If (Len(List1.Text) > 9) Then
Dim shortname As String ' receives short-filename equivalent
Dim slength As Long ' receives length of short-filename equivalent
' Make room in the buffer to receive the 8.3 form of the filename.
shortname = Space(256)
' Get the 8.3 form of the filename specified.
'the file must exist for the api to do it's stuff
slength = GetShortPathName(List1.Text, shortname, 256)
' Remove the trailing null and display the result.
shortname = Left(shortname, slength)
MsgBox shortname, vbInformation, "shortname"
Text1.Text = shortname
Open "C:\fb\testbatch.bat" For Output As #1
Print #1, "c:\hd\psmd.exe" & Space(1) & Text1.Text & Space(1) & ">" & Space(1) & "C:\hB\test.Txt"
Close #1
Shell ("cmd /c C:\fb\testbatch.bat")
End if
End Sub