Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding Sub-Directories of Folders to a List...

Status
Not open for further replies.

ManOverboard

Programmer
Dec 9, 2000
1
US
Okay, I'm making a file managing utility for myself... I was wondering if anyone knew how to add ALL of the folders inside a specified folder to a list? The sub-directories, and then the folders in those sub-directories, and the folders in those filders, etc., until ALL of the folders inside one specified folder have been added. I'm sure this is possible... but does anyone know how to do it? Thanks in advance.
 
I grabbed this out of the "DIR" function of VB in the MSDN
This should do the trick for you. I'm not sure how high it is on the "elegance" scale :)

' Display the names in C:\ that represent directories.
MyPath = "c:\" ' Set the path.
MyName = Dir(MyPath, vbDirectory) ' Retrieve the first entry.
Do While MyName <> &quot;&quot; ' Start the loop.
' Ignore the current directory and the encompassing directory.
If MyName <> &quot;.&quot; And MyName <> &quot;..&quot; 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
End If ' it represents a directory.
End If
MyName = Dir ' Get next entry.
Loop
David Moore
dm7941@sbc.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top