Solved

Multiselect Files in Commondialog.FileName

Posted on 1997-10-15
2
193 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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month9 days, 23 hours left to enroll

624 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