Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7850077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:44:09+00:00 2026-06-02T18:44:09+00:00

I am looping through a set of directories using a File System Object, and

  • 0

I am looping through a set of directories using a File System Object, and I want to specify an additional directory to loop through. For example, I currently have:

Sub test()
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFolder = objFSO.GetFolder(Directory)
    Set colSubfolders = objFolder.Subfolders
    For Each objSubfolder In colSubfolders
        ' take some action
    End For
End Sub

But, I want to specify an additional folder to loop through, such as:

colSubfolders = colSubfolders + "additionalpath"
For Each objSubfolder In colSubfolders ....

Alternatively, is it possible to specify multiple objects in a loop command, such as:

For Each objSubfolder in colSubfolders, "additionalpath"
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T18:44:12+00:00Added an answer on June 2, 2026 at 6:44 pm

    Simplest way is to break out the code that enumerates the directories and the code that “takes some action” and wrap it in a call that repeats what you need;

    Sub foo()
        enumDirs "c:\temp\", "c:\music", "c:\as many as you like ..."
    End Sub
    
    Sub enumDirs(ParamArray strPaths() As Variant)
        Dim i As Long
        For i = 0 To UBound(strPaths)
            enumDir CStr(strPaths(i))
        Next
    End Sub
    
    Sub enumDir(strPath As String)
        Dim objFolder As Object, colSubfolders As Object, objSubfolder As Object
        Set objFolder = CreateObject("Scripting.FileSystemObject").GetFolder(strPath)
        Set colSubfolders = objFolder.Subfolders
        For Each objSubfolder In colSubfolders
            TakeSomeAction strPath, objSubfolder.Name
        Next
    End Sub
    
    sub TakeSomeAction(strRoot As String, strFoundPath As String)
        Debug.Print ">"; strRoot & ", " & strFoundPath
    End sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Per example below...Looping through an object from a parsed JSON string returns an error
I'm having trouble looping through a set of dynamically created UITextFields and storing those
I am looking for a way to set permissions on a virtual directory through
I am looping through a large text file and im looking for lines that
I have a PHP script now looping through combinations of a set of arrays.
So I'm looping through a set of JSON arrays, and then looping through each
I'm looping through an array, and during each iteration of the loop, I'm calling
I am looping through my XML file to capture a list of deposits and
I've got a recordset I'm looping through using .movenext and all, but it always
I want to set a string to the entire contents of a file without

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.