Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ben Ben is offline
external usenet poster
 
Posts: 509
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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   Report Post  
Posted to microsoft.public.excel.programming
Ben Ben is offline
external usenet poster
 
Posts: 509
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
survey traverse computations SRH Excel Discussion (Misc queries) 0 February 27th 10 01:54 AM
How to traverse cell.Dependents joeu2004 Excel Programming 4 February 15th 08 12:10 PM
traverse data based on 2 conditions olga Excel Discussion (Misc queries) 5 January 9th 07 04:12 PM
traverse until non integer evil baby[_6_] Excel Programming 1 March 1st 06 04:00 PM
Traverse treeview bottom to top RB Smissaert Excel Programming 2 August 23rd 03 07:34 PM


All times are GMT +1. The time now is 06:08 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"