select multiple files *RESOLVED*
Back again for more.
Does anybody know what modifications I need to add to this code to allow the user to either open a single file or select multiple files.
Code so far
VB Code:
Private Sub Command1_Click()
Dim strFile As String
On Error Resume Next
With CommonDialog1
.Flags = cdlOFNExplorer
.Filter = "Mp3 (*.mp3)|*.mp3"
.InitDir = "C:\"
.DialogTitle = "Select File"
.ShowOpen
If Not .FileName = "" Then
strFile = Mid(.FileName, InStrRev(.FileName, "\") + 1)
If Dir(FAVORITES_FOLDER & strFile) = "" Then
FileCopy .FileName, FAVORITES_FOLDER & strFile
End If
End If
End With
End Sub
Cheers
Rob
Re: select multiple files
make a do while lenb(file) > 0 loop
Re: select multiple files
where will I need to put that
Re: select multiple files
You need to use the cdlOFNAllowMultiSelect flag. The help file states that the filenames are separated with spaces which is not correct when you use the Explorer style. Instead the filenames are separated with NULL characters. The first part only contains the path and the rest are the different filenames selected.
VB Code:
Private Sub Command1_Click()
Dim strFile() As String, strPath As String
Dim n As Long, nCount As Long
On Error Resume Next
With CommonDialog1
.Flags = cdlOFNAllowMultiselect + cdlOFNExplorer
.CancelError = True
.InitDir = "C:\"
.DialogTitle = "Select File"
.ShowOpen
If Err.Number <> cdlCancel Then
strFile = Split(.FileName, vbNullChar)
nCount = UBound(strFile)
If nCount = 0 Then
'Only one file is selected so split up the path and the filename
ReDim strFile(1)
strFile(0) = Left$(.FileName, InStrRev(.FileName, "\"))
strFile(1) = Mid$(.FileName, InStrRev(.FileName, "\") + 1)
nCount = 1
End If
strPath = strFile(0)
If Right$(strPath, 1) <> "\" Then
strPath = strPath & "\"
End If
For n = 1 To nCount
If Len(Dir(FAVORITES_FOLDER & strFile(n))) = 0 Then
FileCopy strPath & strFile(n), FAVORITES_FOLDER & strFile(n)
End If
Next
End If
End With
End Sub
Cheers,
1 Attachment(s)
Re: select multiple files
Doesn't seem to want to work, I have attached my prog could you check I've done it right.
Cheers
Rob
Re: select multiple files
It does work. I made one little misstake in the initial code I wrote but I changed that. Maybe you copied the code before I had the time to edit my origional post. Copy the code above and paste it into your form.
Re: select multiple files
Re: select multiple files *RESOLVED*
just a quickie can you use similar so the user can remove files from the folder?
Cheers
Rob
Re: select multiple files *RESOLVED*
Kill strPath & strFile(n)
Re: select multiple files *RESOLVED*
Could I use the code for opening files as a base or is it totally different?