Results 1 to 10 of 10

Thread: select multiple files *RESOLVED*

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Resolved 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:
    1. Private Sub Command1_Click()
    2. Dim strFile As String
    3.  
    4. On Error Resume Next
    5.  
    6.     With CommonDialog1
    7.         .Flags = cdlOFNExplorer
    8.         .Filter = "Mp3 (*.mp3)|*.mp3"
    9.         .InitDir = "C:\"
    10.         .DialogTitle = "Select File"
    11.    
    12.         .ShowOpen
    13.         If Not .FileName = "" Then
    14.             strFile = Mid(.FileName, InStrRev(.FileName, "\") + 1)
    15.             If Dir(FAVORITES_FOLDER & strFile) = "" Then
    16.                 FileCopy .FileName, FAVORITES_FOLDER & strFile
    17.             End If
    18.         End If
    19.     End With
    20.  
    21. End Sub

    Cheers
    Rob
    Last edited by robvr6; Jan 15th, 2005 at 12:42 PM. Reason: resolved

  2. #2

    Re: select multiple files

    make a do while lenb(file) > 0 loop

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: select multiple files

    where will I need to put that

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    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:
    1. Private Sub Command1_Click()
    2.     Dim strFile() As String, strPath As String
    3.     Dim n As Long, nCount As Long
    4.     On Error Resume Next
    5.     With CommonDialog1
    6.         .Flags = cdlOFNAllowMultiselect + cdlOFNExplorer
    7.         .CancelError = True
    8.         .InitDir = "C:\"
    9.         .DialogTitle = "Select File"
    10.        
    11.         .ShowOpen
    12.         If Err.Number <> cdlCancel Then
    13.             strFile = Split(.FileName, vbNullChar)
    14.             nCount = UBound(strFile)
    15.             If nCount = 0 Then
    16.                 'Only one file is selected so split up the path and the filename
    17.                 ReDim strFile(1)
    18.                 strFile(0) = Left$(.FileName, InStrRev(.FileName, "\"))
    19.                 strFile(1) = Mid$(.FileName, InStrRev(.FileName, "\") + 1)
    20.                 nCount = 1
    21.             End If
    22.             strPath = strFile(0)
    23.             If Right$(strPath, 1) <> "\" Then
    24.                 strPath = strPath & "\"
    25.             End If
    26.             For n = 1 To nCount
    27.                 If Len(Dir(FAVORITES_FOLDER & strFile(n))) = 0 Then
    28.                     FileCopy strPath & strFile(n), FAVORITES_FOLDER & strFile(n)
    29.                 End If
    30.             Next
    31.         End If
    32.     End With
    33. End Sub
    Cheers,

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    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
    Attached Files Attached Files

  6. #6
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    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.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: select multiple files

    Thanks very much!!

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: select multiple files *RESOLVED*

    just a quickie can you use similar so the user can remove files from the folder?

    Cheers
    Rob

  9. #9
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: select multiple files *RESOLVED*

    Kill strPath & strFile(n)

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    277

    Re: select multiple files *RESOLVED*

    Could I use the code for opening files as a base or is it totally different?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width