Solved

A question about Recurse All SubDirectories?

Posted on 2002-06-11
2
132 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Updates not working for MS Windows 7 12 182
Modifying Conditional Format from VBA code 3 60
Help me. 3 60
Formula problem with Excel attachment 6 39
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

828 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