Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Multiselect Files in Commondialog.FileName

Posted on 1997-10-15
2
Medium Priority
?
195 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 300 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
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…
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

722 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