Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to traverse subdirectories
Hi all,
I need to go to a particular directory then from there I would like to traverse all the subdirectories beneath it. can you show me how? I would also like to use a debug.print statement print out the paths. Thanks for share your thoughts. Ben |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to traverse subdirectories
You can use the following code. Sub AAAA is the starting point where you
specify the starting folder. The ListSubFolders procedure recursively lists all the subfolders (and subfolders of subfolders etc). Sub AAAA() Dim FSO As Scripting.FileSystemObject Dim StartFolderName As String Dim StartFolder As Scripting.Folder StartFolderName = "C:\FrontPage Webs" '<<<<<<<<< CHANGE Set FSO = New Scripting.FileSystemObject Set StartFolder = FSO.GetFolder(StartFolderName) Debug.Print "Start: " & StartFolder.Path ListSubFolders StartFolder End Sub Sub ListSubFolders(OfFolder As Scripting.Folder) Dim SubFolder As Scripting.Folder For Each SubFolder In OfFolder.SubFolders Debug.Print SubFolder.Path If SubFolder.SubFolders.Count 0 Then ListSubFolders SubFolder End If Next SubFolder End Sub See also http://www.cpearson.com/Excel/FolderTree.aspx for example code for many ways to list subfolders and/or files. -- Cordially, Chip Pearson Microsoft Most Valuable Professional Excel Product Group Pearson Software Consulting, LLC www.cpearson.com (email on web site) "Ben" wrote in message ... Hi all, I need to go to a particular directory then from there I would like to traverse all the subdirectories beneath it. can you show me how? I would also like to use a debug.print statement print out the paths. Thanks for share your thoughts. Ben |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to traverse subdirectories
Chip,
Thanks so much. That was exactly what I was looking for. Ben -- "Chip Pearson" wrote: You can use the following code. Sub AAAA is the starting point where you specify the starting folder. The ListSubFolders procedure recursively lists all the subfolders (and subfolders of subfolders etc). Sub AAAA() Dim FSO As Scripting.FileSystemObject Dim StartFolderName As String Dim StartFolder As Scripting.Folder StartFolderName = "C:\FrontPage Webs" '<<<<<<<<< CHANGE Set FSO = New Scripting.FileSystemObject Set StartFolder = FSO.GetFolder(StartFolderName) Debug.Print "Start: " & StartFolder.Path ListSubFolders StartFolder End Sub Sub ListSubFolders(OfFolder As Scripting.Folder) Dim SubFolder As Scripting.Folder For Each SubFolder In OfFolder.SubFolders Debug.Print SubFolder.Path If SubFolder.SubFolders.Count 0 Then ListSubFolders SubFolder End If Next SubFolder End Sub See also http://www.cpearson.com/Excel/FolderTree.aspx for example code for many ways to list subfolders and/or files. -- Cordially, Chip Pearson Microsoft Most Valuable Professional Excel Product Group Pearson Software Consulting, LLC www.cpearson.com (email on web site) "Ben" wrote in message ... Hi all, I need to go to a particular directory then from there I would like to traverse all the subdirectories beneath it. can you show me how? I would also like to use a debug.print statement print out the paths. Thanks for share your thoughts. Ben |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
survey traverse computations | Excel Discussion (Misc queries) | |||
How to traverse cell.Dependents | Excel Programming | |||
traverse data based on 2 conditions | Excel Discussion (Misc queries) | |||
traverse until non integer | Excel Programming | |||
Traverse treeview bottom to top | Excel Programming |