[RESOLVED] Selecting various files in a CommonDialog
In a commondialog I set this flag:
CommonDialog1.FLAGS = cdlOFNAllowMultiselect
so various files can be selected. Then, in
CommonDialog1.FileName
the path and the names of the selected files are returned separated by null characters:
Path & Chr(0) & File1 & Chr(0) & ... & Chr(0) & FileN
so that I can retrive the individual file names using a split statement.
Is there an easier way I'm not aware of?
Re: Selecting various files in a CommonDialog
That would the easiest way, IMHO.
Re: Selecting various files in a CommonDialog
I agree, and here is how I would do it
Code:
Dim i As Long
Dim sArrFileList() As String
sArrFileList = Split(CommonDialog1.FileName, Chr(0))
For i = 0 To UBound(sArrFileList())
List1.AddItem sArrFileList(i) 'Listbox used as an example only
Next
Re: Selecting various files in a CommonDialog
Quote:
Originally Posted by Hack
I agree, and here is how I would do it
Code:
Dim i As Long
Dim sArrFileList() As String
sArrFileList = Split(CommonDialog1.FileName, Chr(0))
For i = 0 To UBound(sArrFileList())
List1.AddItem sArrFileList(i) 'Listbox used as an example only
Next
Yeah, that's more or less my approach. But some care had to be taken anyway. I can't remember what the trouble was so I just transcribe the working code.
Code:
ohndc = Split(CommonDialog1.FileName, Chr$(0))
NFiles = UBound(ohndc)
If NFiles = 0 Then
NFiles = 1
'Working with option base 1
ReDim FileFullPath(1 To NFiles)
ReDim File(1 To NFiles)
FileFullPath(1) = CommonDialog1.FileName
File(1) = CommonDialog1.FileTitle
Else
ReDim FileFullPath(1 To NFiles)
ReDim File(1 To NFiles)
PathOnly = ohndc(0) & "\"
For i = 1 To UBound(ohndc)
File(i) = ohndc(i)
FileFullPath(i) = PathOnly & File(i)
Next
End If