Solved

A question about Recurse All SubDirectories?

Posted on 2002-06-11
2
130 Views
Last Modified: 2010-05-02
This code will recursively parse a directory defined by an path parameter.

Function RecurseFolderList(foldername)

    Dim fso, f, fc, fj, f1

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.GetFolder(foldername)
    Set fc = f.Subfolders
    Set fj = f.Files

    'For each subfolder in the Folder
    For Each f1 In fc
        'Do something with the Folder Name
        debug.print f1
        'Then recurse this function with the sub
        '-folder to get any sub-folders
        RecurseFolderList(f1)
    Next    
   
    'For each folder check for any files
    For Each f1 In fj
        debug.print f1
    Next

End Function

But I don't know how to stop the recursive function when a SubDirectorie/file is found

Could any can tell me how to do?

Thanks a lot!
0
Comment
Question by:Jerryleo
2 Comments
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 50 total points
ID: 7069486
Function RecurseFolderList(foldername, byref pBlnFound as boolean)

   Dim fso, f, fc, fj, f1

   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f = fso.GetFolder(foldername)
   Set fc = f.Subfolders
   Set fj = f.Files

   'For each subfolder in the Folder
   For Each f1 In fc
       'Do something with the Folder Name
       debug.print f1
       if f1 = "what you are looking for" then
           pblnfound = true
       else
           'Then recurse this function with the sub
           '-folder to get any sub-folders
           RecurseFolderList(f1, pblnfound)
       endif
       if pblnfound then exit for
   Next    
   
   'For each folder check for any files
   For Each f1 In fj
       debug.print f1
   Next

End Function
0
 

Author Comment

by:Jerryleo
ID: 7075692
Thank you very much
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now