Solved

Multiselect Files in Commondialog.FileName

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now