Solved

Multiselect Files in Commondialog.FileName

Posted on 1997-10-15
2
187 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

752 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