Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 385
  • Last Modified:

VB6 Multiple folder selector Dialog

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
ianmac42
Asked:
ianmac42
  • 3
  • 3
  • 2
1 Solution
 
BlueScreen_Commented:
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
 
brianb99999Commented:
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
 
ianmac42Author Commented:
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
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.

 
ianmac42Author Commented:
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
 
brianb99999Commented:
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
 
ianmac42Author Commented:
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
 
brianb99999Commented:
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
 
BlueScreen_Commented:
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

Technology Partners: 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!

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now