Sub Folders

I need to know all the subfolder names within a folder, does anyone have an efficient way to do it?

Thanks in advance
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Have a list box on the form. copy and paste the following code. click on the form in the run mode
Option Explicit
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const LB_DIR = &H18D
Private Const LB_RESETCONTENT = &H184
Private Const DDL_DIRECTORY = &H10
Private Const DDL_EXCLUSIVE = &H8000
Private Sub Form_Click()
Dim numfound As Long
Dim searchPath As String
searchPath = "C:\windows\*.*"
Call SendMessage(List1.hwnd, LB_RESETCONTENT, 0, ByVal 0)
numfound = SendMessage(List1.hwnd, LB_DIR, DDL_FLAGS, ByVal searchPath)
MsgBox numfound & " directories found"
End Sub
Here is a function which does the job -

Private Sub FindSubFolders(ByVal strPathName As String)
    Dim strSubFolders() As String
    Dim strTempSubFolder As String
    Dim intNumOfSubFolders As Integer
    Dim intSubFolderVount As Integer
    intNumOfSubFolders = -1
    strTempSubFolder = Dir(strPathName, vbDirectory)
    While Len(strTempSubFolder) <> 0
        intNumOfSubFolders = intNumOfSubFolders + 1
        ReDim Preserve strSubFolders(intNumOfSubFolders)
        strSubFolders(intNumOfSubFolders) = strTempSubFolder
        strTempSubFolder = Dir()
'   Prepare the list of sub folders
    For intSubFolderCount = 0 To intNumOfSubFolders
        strTempSubFolder = strTempSubFolder & ", " & strSubFolders(intSubFolderCount)
    Next intSubFolderCount
    MsgBox "The number of sub folders in " & strPathName & " are " & (intNumOfSubFolders + 1) & ". They are - " & strTempSubFolder
End Sub


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ravisaAuthor Commented:
Thanks very much
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.