Article ID: 198974
Article Last Modified on 7/15/2004
c:\my files\my file.txt
c:\my files<null>my file.txt<null>my file.rtf
'*** Start Code ****
Option Explicit
Private Sub Command1_Click()
Dim current As Integer
Dim I As Integer
Dim intIndex As Integer
Dim iStart As Integer
Dim FileNames$()
Dim sFname As String
Dim iEndPath As Integer
Text2.Text = ""
With CommonDialog1
.MaxFileSize = 2048 ' Set as appropriate
.filename = ""
.Filter = "All Files|*.*"
.Flags = cdlOFNAllowMultiselect + cdlOFNExplorer
.ShowOpen
sFname = .filename & vbNullChar
End With
iEndPath = 1
' determine if multiple files were selected
' null delimiter is not inserted if only 1 file is selected
If countDelimiters(sFname, vbNullChar) = 1 Then
Do Until (iEndPath = 0)
iStart = iEndPath + 1
iEndPath = InStr(iEndPath + 1, sFname, "\")
Loop
ReDim Preserve FileNames(0)
' determine if root directory was selected - preserve the "\"
If countDelimiters(sFname, "\") = 1 Then
FileNames(0) = Mid(sFname, 1, iStart - 1)
Else
FileNames(0) = Mid(sFname, 1, iStart - 2)
End If
Else
iStart = InStr(1, sFname, vbNullChar) + 1
ReDim Preserve FileNames(0)
FileNames(0) = Left(sFname, iStart - 2)
End If
intIndex = 1
For I = iStart To Len(sFname)
If Mid(sFname, I, 1) = vbNullChar Then
ReDim Preserve FileNames(intIndex)
FileNames(intIndex) = Mid(sFname, iStart, I - iStart)
iStart = I + 1
intIndex = intIndex + 1
End If
Next I
' display information in proper text box
For I = 0 To UBound(FileNames)
If I Then
Text2.Text = Text2.Text & FileNames(I) & vbCrLf
Else
Text1.Text = FileNames(I)
End If
Next I
End Sub
Function countDelimiters(ByVal sFiles As String, _
ByVal vSearchChar As Variant) As Integer
Dim iCtr As Integer
Dim iResult As Integer
For iCtr = 1 To Len(sFiles)
If Mid(sFiles, iCtr, 1) = vSearchChar Then iResult = iResult + 1
Next iCtr
countDelimiters = iResult
End Function
'*** End Code ***
Additional query words: cdlOFNLongNames
Keywords: kbhowto kbcmndlgfileo kbcmndlg kbctrl KB198974