Solved

A question about Recurse All SubDirectories?

Posted on 2002-06-11
2
135 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month6 days, 15 hours left to enroll

622 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