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
iamatrampAsked:
Who is Participating?
 
David LeeConnect With a Mentor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.