Thread
:
Dir
View Single Post
#
4
Posted to microsoft.public.excel.programming
Ardus Petus
external usenet poster
Posts: 718
Dir
Dim fso As Scripting.FileSystemObject
Sub test()
Set fso = New Scripting.FileSystemObject
Finddir ("c:\")
End Sub
Sub Finddir(MyPath As String)
Dim fDir As Folder
Dim fSubDir As Folder
Set fDir = fso.GetFolder(MyPath)
Debug.Print fDir.Path
For Each fSubDir In fDir.SubFolders
Finddir fSubDir.Path
Next fSubDir
End Sub
HTH
--
AP
"greasybeano" a écrit dans le message de
news:
...
I have taken the following code from the Dir help file which works ok at
first level.
However, I need to search for all the associated subdirectories but not
too
sure how to adapt the code. could someone be kind enough to assist please?
Many thanks.
--
GB
Sub Finddir()
MyPath = "c:\" ' Set the path.
myname = Dir(MyPath, vbDirectory) ' Retrieve the first entry.
Do While myname < "" ' Start the loop.
' Ignore the current directory and the encompassing directory.
If myname < "." And myname < ".." Then
' Use bitwise comparison to make sure MyName is a directory.
If (GetAttr(MyPath & myname) And vbDirectory) = vbDirectory Then
Debug.Print myname ' Display entry only if it ' it
represents
a directory.
End If
End If
myname = Dir ' Get next entry.
Loop
End Sub
Reply With Quote
Ardus Petus
View Public Profile
Find all posts by Ardus Petus