LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Sub Directories

so you don't repeat your code for the file processing part, you can make the
sub a recursive one...

Sub ProcessFiles(strFolder As String)
Dim oFSO As New FileSystemObject
Dim oFolder As Folder
Dim oSubFolder As Folder
Dim oFile As File


Set oFolder = oFSO.GetFolder(strFolder)

'process files in the starting folder
For Each oFile In oFolder.Files
'do stuff
Debug.Print oFile.Path
Next oFile

'process sub folders
For Each oSubFolder In oFolder.SubFolders
ProcessFiles oSubFolder.Path
Next oSubFolder
End Sub

you then would use it like this:

Sub test()
ProcessFiles "c:\mystuff"
End Sub



--
Hope that helps.

Vergel Adriano


"Vergel Adriano" wrote:

Mike,

Add a reference to the Windows Script Host Object Model and then try
something like this:

Sub ProcessFiles()
Dim oFSO As New FileSystemObject
Dim oFolder As Folder
Dim oSubFolder As Folder
Dim oFile As File

Set oFolder = oFSO.GetFolder("C:\mystuff")

'process files in the starting folder
For Each oFile In oFolder.Files
'do stuff
Debug.Print oFile.Path
Next oFile

'process files in sub folders
For Each oSubFolder In oFolder.SubFolders
For Each oFile In oSubFolder.Files
'do stuff
Debug.Print oFile.Path
Next oFile
Next oSubFolder
End Sub

--
Hope that helps.

Vergel Adriano


"Mike H." wrote:

I need to look at all files within a directory and I need to "climb" down
sub-directories within those directories. For example:
FileDir="C:\mystuff"
I am using this loop:
FName = Dir(FileDir)
Do Until FName = ""
do stuff
Loop
But if there is a folder "c:\mystuff\subdir\" I need to look there too.
How do I determine sub-directories (folders) within folders?


 
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
Creating Directories wardides[_6_] Excel Programming 1 October 15th 04 12:24 AM
sub directories again Shailesh Shah[_2_] Excel Programming 5 February 9th 04 09:32 PM
sub directories again Mike[_67_] Excel Programming 2 February 7th 04 12:06 AM
sub directories Mike Excel Programming 5 February 6th 04 10:15 PM
Directories Jeff[_24_] Excel Programming 4 January 20th 04 09:26 AM


All times are GMT +1. The time now is 08:20 PM.

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

About Us

"It's about Microsoft Excel"