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
Solved

VB6 Multiple folder selector Dialog

Posted on 2004-08-30
8
354 Views
Last Modified: 2013-12-25
I need a VB6 program or function that presents a user with a Folder Browser that enables the user to select multiple folders by either dragging a box around the folders or shift clicking the desired folders. A collection of path statements should be returned after clicking OK. The user should be able to set an initial path.
0
Comment
Question by:ianmac42
  • 3
  • 3
  • 2
8 Comments
 
LVL 2

Accepted Solution

by:
BlueScreen_ earned 500 total points
ID: 11937756
This will show a message box with all the file you selected.
If you have any question let us know!

Dim initpath As String
Dim filname As String
Dim fileArray() As String

    With CommonDialog1
        .InitDir = initpath  'set the initial path
        .FileName = ""  'rest the file name
        .Filter = "All Files (*.*)|*.*|"  ' change this to your filter
        .flags = cdlOFNAllowMultiselect Or cdlOFNExplorer  ' enable multiselect
        .ShowOpen  'display the open dialog
        filname = .FileName
    End With
       
   ' Each file are separated by a null char( chr$(0)  )
   fileArray = Split(filname, Chr$(0))
       
    ' display all the file you selected
    ' this section can be removed
    For i = LBound(fileArray) + 1 To UBound(fileArray)
        ' the first element is the path
        ' the others are the file name
        MsgBox fileArray(0) & "\" & fileArray(i)
    Next
0
 
LVL 5

Expert Comment

by:brianb99999
ID: 11938276
Hi ianmac42,

Unfortunately, don't have enough time to write it, but, it would be pretty simple (load the folders into a treeview, make the treeview multiselect, return the selected treeview item's in a string).
You need to create an Active X control (using treeview or listview) to do this for you.
A good example of some of the code that will need is on:
http://www.freevbcode.com/ShowCode.asp?ID=6866
Remember when you add the list boxes make them multiselect.

There is nothing within VB or Windows API's that can select multiple folders.

Brian.
0
 

Author Comment

by:ianmac42
ID: 11947007
Brian,
In Windows Explorer in Windows XP I can select multiple folders in the right hand pane. Isn't this functionality available to VB through the Shell object?
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

Author Comment

by:ianmac42
ID: 11947350
Bluescreen,
Thanks for the code but it doesn't work. I get the dialog which allows me to select multiple folders but there's no "OK" button to exit the dialog and return the selected path strings. The only buttons available are "OPEN" & "CANCEL", if I click "OPEN" then the last folder that I selected is opened.
0
 
LVL 5

Expert Comment

by:brianb99999
ID: 11947694
Hi ianmac42,

Isn't this functionality available to VB through the Shell object?
No - using the shell object simply opens another program and while you can use it to open Explorer - explorer will not return any values to your program.

Bluescreen,
Thanks for the code but it doesn't work. I get the dialog which allows me to select multiple folders but there's no "OK" button to exit the dialog and return the selected path strings. The only buttons available are "OPEN" & "CANCEL", if I click "OPEN" then the last folder that I selected is opened.
The code Bluescreen gave you is to select multiple files not multiple folders.

The suggestion I made earlier is what is commonly used to solve this problem.
The following wont work:
-You can't use the common dialog control - it will select multiple files but not multiple folders.
-You can't use SHBrowseForFolder API - It only allows you to select 1 folder.
-You can't shell to explorer - it won't return any values.
-You can't use FileSystemObject API (You can use it to copy multiple folder - but not select them).

Hope that helps,

Brian.
0
 

Author Comment

by:ianmac42
ID: 12038646
Brian,
Thanks for your help, I've used the CCRP DirTreeView component for the directory browser, MS ListView component for the subdirectory folder list and your recursion program and everything works sweetly. Sorry I doubted you earlier but I had conficting reports.

Ian
0
 
LVL 5

Expert Comment

by:brianb99999
ID: 12040220
Hi Ian,

No problem, glad it helped.
Conflicting reports are a good thing, someone will always find a new way to do something.

Brian.
0
 
LVL 2

Expert Comment

by:BlueScreen_
ID: 12040235
thanks for the points ianmac42.
i feel a little bit bad about getting those points since i give you a solution for files and not for folders like you asked... but i'll be glad if it helped you in any way.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…

856 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