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

  • SEARCH
  • Home
  • 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 8128245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:48:57+00:00 2026-06-06T07:48:57+00:00

How can one make recursive Glob() in a VariantDir() environment in Python? The answer

  • 0

How can one make recursive Glob() in a VariantDir() environment in Python?

The answer from the question <Use a Glob() to find files recursively in Python?> will not work, because you need use Glob() to get a list of files that is aware of VariantDir() environment.

So you need something like:

import fnmatch
import os

matches = []
for root, dirnames, filenames in os.walk('src'):
  for filename in fnmatch.filter(filenames, '*.c'):
    matches.append(os.path.join(root, filename))

matches = Glob(matches)

Will this work?

  • 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-06T07:48:58+00:00Added an answer on June 6, 2026 at 7:48 am

    Your approach would work with a minor tweak as follows:

    import fnmatch
    import os
    
    def RecursiveGlob(pathname)
        matches = []
        for root, dirnames, filenames in os.walk(pathname):
            for filename in fnmatch.filter(filenames, '*.c'):
                matches.append(File(os.path.join(root, filename)))
    
        return matches
    

    Notice that I converted it to a File(), since the SCons Glob() function returns Nodes if the “strings” parameter is false.

    To be able to handle the VariantDir, etc and to better integrate the functionality with the existing SCons Glob() functionality, you could actually incorporate a call to the existing Glob() function, like this:

    # Notice the signature is similar to the SCons Glob() signature,
    # look at scons-2.1.0/engine/SCons/Node/FS.py line 1403
    def RecursiveGlob(pattern, ondisk=True, source=True, strings=False):
        matches = []
        # Instead of using os.getcwd() consider passing-in a path
        for root, dirnames, filenames in os.walk(os.getcwd()):
            cwd = Dir(root)
            # Glob() returns a list, so using extend() instead of append()
            # The cwd param isnt documented, (look at the code) but its 
            # how you tell SCons what directory to look in.
            matches.extend(Glob(pattern, ondisk, source, strings, cwd))
    
        return matches
    

    You could take it one step further and do the following:

    def MyGlob(pattern, ondisk=True, source=True, strings=False, recursive=False):
        if not recursive:
            return Glob(pattern, ondisk, source, strings)
    
        matches = []
        # Instead of using os.getcwd() consider passing-in a path
        for root, dirnames, filenames in os.walk(os.getcwd()):
            cwd = Dir(root)
            # Glob() returns a list, so using extend() instead of append()
            # The cwd param isnt documented, (look at the code) but its 
            # how you tell SCons what directory to look in.
            matches.extend(Glob(pattern, ondisk, source, strings, cwd))
    
        return matches
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can we make one database restore date to date, like sunday to wednesday
Can any one tell me how can I make divs visible in ASP.NET. I
http://jsfiddle.net/DaJWC/ i can't figure out how to make one of the links reverse so
I am new to android.So i can any one sho me how to make
In Java, how can you make an ArrayList read-only (so that no one can
All I can make out is that one of them is the BC for
How can I make a vertical UISlider? I saw it in one of the
Hai every one. How can I make the changes in the aumix permanently? I
Possible Duplicate: Sleep Less Than One Millisecond How can I make a program sleep
Take the following demo code (from the GIO answer to this question), which uses

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.