I am trying to list all the folders in a particular path subfolders. Unfortunately, I have a problem when the recursion gets to the last folder. The next dir returns an invalid procedure error. Here's the code:
Can anyone see what the problem is or share some code that can help.
Thanks,
Rewdee
Code:
Sub FindFolders(sFileStart As String)
Dim MyPath As String, MyName As String
MyPath = sFileStart MyName = Dir(MyPath, vbDirectory) Do While MyName <> ""
If MyName <> "." And MyName <> ".." Then
If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
Debug.Print MyName
FindFolders MyPath & MyName & "\"
End If
End If
MyName = Dir
Loop
End Sub
Sub test()
FindFolders "C:\My Documents\"
End Sub
Can anyone see what the problem is or share some code that can help.
Thanks,
Rewdee