Learn how to a build a cloud-first strategyRegister Now

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

Add Subfolders into List

Hi,

I have a textbox, list, and command button on my form.
I want it so when you press the command button, whatever directory in the textbox e.g. C:\Documents and Settings\All Users\ I want all the folders and sub folders to come up in the list box as follows:

C:\Documents and Settings\All Users\Local Settings\
C:\Documents and Settings\All Users\Documents\
C:\Documents and Settings\All Users\Documents\My Music\

and so on....
How do i do this?

thanks,
iamatramp
0
iamatramp
Asked:
iamatramp
1 Solution
 
David LeeCommented:
Greetings, iamatramp.

Something like this will do it.  

Dim objFSO As Object

Private Sub Command1_Click()
    LoadFolders Text1.Text
End Sub

Sub LoadFolders(strPath As String)
    Dim objRootFolder As Object, _
        objFolder As Object
    Set objRootFolder = objFSO.GetFolder(strPath)
    For Each objFolder In objRootFolder.SubFolders
        List1.AddItem objFolder.Path
        LoadFolders objFolder.Path
    Next
End Sub

Private Sub Form_Load()
    Set objFSO = CreateObject("Scripting.FileSystemObject")
End Sub


Cheers!
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

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