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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looping through sub folders

Status
Not open for further replies.

flybravo

Programmer
Jun 30, 2003
35
US
Does anyone know how to write a procedure that will loop throught all folders and files, if a user enters a parent folder location
This is what I have so far, I can only loop through the top folders. Each parent folders will have a different structure.

<CODE>
Dim currDir as New DirectoryInfo(me.textbox1.text)
Dim di as directoryInfo

For Each di in currDir.GetDirectories
MsgBox di.full.name
Next
</CODE>
 
Hi,

Loop a folder structure by making a recursive call to a sub that loops the subfolders of the parent folder (did make sence?):
-----------------------------------------------------------
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
LoopSubFolders(&quot;D:\&quot;)
End Sub

Private Sub LoopSubFolders(ByVal ParentDir As String)
Dim d As String
Try
For Each d In IO.Directory.GetDirectories(ParentDir)
ListBox1.Items.Add(d) 'Add the sub folder
LoopSubFolders(d) 'Add all the subFolder's subfolders
Next
Catch e As Exception
End Try
End Sub
-----------------------------------------------------------

Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top