Solved

Multiselect Files in Commondialog.FileName

Posted on 1997-10-15
2
185 Views
Last Modified: 2012-06-27
Hello experts,
I am using vb 5.0.  In my form i am using commondialog with
CommonDialog.Flags = cdlOFNExplorer Or                      cdlOFNAllowMultiselect
following flags set.
Once i select multiple files and perform
debug.print commondialog.filename it gives me all the selected files with a funny character delimination between all files.  
Question:
What is that deliminator and how do i get the file names individually and the path?

Thankyou
0
Comment
Question by:msali
  • 2
2 Comments
 
LVL 6

Accepted Solution

by:
anthonyc earned 100 total points
ID: 1437735
Multi Selected files in a common dialog are delimited by spaces:

This is what the help file says:

Specifies that the File Name list box allows multiple selections.The user can select more than one file at run time by pressing the SHIFT key and using the UP ARROW and DOWN ARROW keys to select the desired files. When this is done, the FileName property returns a string containing the names of all selected files. The names in the string are delimited by spaces.

Once you do the .ShowOpen, check the .Filename.  If there is a space in it, then you have selected multiple files.  Use this code

public sub GetFiles(strFileArray() as string)
   dim intI as integer
   dim intJ as integer
   dim intCount as integer
   dim strFile as string
   dim strPath as string

   with dlgFile
       .flags = CDLOFNAllowMultiSelect + CDLOFNExplorer
       .filter = "All Files (*.*)|*.*"
       .filterindex = 1
       .dialogtitle = "Select all the files you want"
       .showopen

       strFile = .filename

       if instr(strFile, " ") = 0 then
           'only 1 file selected
           redim strFileArray(1 to 1) as string
           strFileArray(1) = strFile
      else
          'More than 1 file.  The first item is the path, all other items are files
         intI = instr(strFile, " ")
         strPath = left$(strFile, intI - 1)
         intCount = 0        
         redim strFileArray(1 to 1) as string 'clear it

         do until  intI = 0
             intCount = intCount + 1
             intJ = instr(intI + 1, strFile, " ")

             redim preserve strFileArray(1 to intCount) as string          
             strFileArray(intCount) = strPath  & mid$(strFile, intI + 1, iif(intJ = 0, len(strFile) + 1, intJ))
             intI = intJ
         loop
     end if
end sub

This sub will produce an array, strFileArray, with all the files in it.        
   
Notes:
Since they are delimited by spaces, this can cause trouble with win95 filenames that have spaces in them.


0
 
LVL 6

Expert Comment

by:anthonyc
ID: 1437737
What I gave you works with the space in the path and then the spaces in the filenames.  It works with long file names, UNLESS the long file names have a space in them.  This is in the knowledge base of Microsoft.  I really can't help more than I already did.  What I gavey ou handles the spaces between the path and first file, or if there is only one file.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question