Thread: Dir
View Single Post
  #18   Report Post  
Posted to microsoft.public.excel.programming
greasybeano greasybeano is offline
external usenet poster
 
Posts: 7
Default Dir

it was that simple! works as intended! many thanks to you all.

regards
--
GB


"Ardus Petus" wrote:

Ooops: I forgot:
In VBE, ToolsReferences
tick Microsoft Scripting Runtime

HTH
--
AP

"greasybeano" a écrit dans le message de
news: ...
thanks for all who replied however, still not too clear what i need to do
(my
VB tad limited) I tried sample code provided by Ardus but get Error
"user-defined type not defined" Ron's solution looks the business but
again
not too sure how I would adapt it for my need.
I just need to show all the sub folders (from "C\" ) associated to each
first level directory. these folders may or may not contain any files - I
should mention i am using xl2003.

many thanks

--
GB


"Ardus Petus" wrote:

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