Solved

A question about Recurse All SubDirectories?

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

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

744 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

12 Experts available now in Live!

Get 1:1 Help Now