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 7965985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:18:03+00:00 2026-06-04T06:18:03+00:00

I have one main directory called Forfun . Inside this directory, there are 7-8

  • 0

I have one main directory called Forfun. Inside this directory, there are 7-8 sub-directorates as Test1, Test2, Test3 and so on. Note there are some files in Forfun as well, that are not sub-directorates. For example, there’s a .txt file lying inside Forfun at the same level as the Test1, Test2 subdirectories.

Every TestX sub-directory is further divided into 3 sub-directories, namely: inputs, results and parameters.

I want to be able to list all the instances of a particular folder like inputs.

The code should recursively go thru the entire Forfun directory and list where all it found the inputs or results directory.

I tried using os.listdir like this:

path = '/myfiles/Forfun'
folders = [f for f in os.listdir(path) if f.endswith('inputs')]
folders 

But this returns me an empty list. Hope I explained the problem clearly, thanks for the help.

  • 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-04T06:18:04+00:00Added an answer on June 4, 2026 at 6:18 am

    os.listdir() lists all files and directories in the provided directory. As you’ve experienced, it does not perform a recursion. It stays on the level of the initially provided directory.

    In order to recursively go through a directory tree and iterate through all files and directories below a certain directory level, you should use Python’s os.walk():

    import os
    
    def listdirs(suffix):
        for dirname, dirnames, filenames in os.walk('.'):
            for subdirname in dirnames:
                subdirpath = os.path.join(dirname, subdirname)
                if subdirpath.endswith(suffix):
                    yield subdirpath
    
    
    if __name__ == "__main__":
        for d in listdirs('inputs'):
            print d
    

    I’ve set up the same directory structure you’ve been proposing. This is the output of the code above:

    $ python test.py 
    ./Test1/inputs
    ./Test2/inputs
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a design of activities like this I have one main activity and
I have one main parent swf that loads several other swfs. If something happens
I have one main outstanding issue, I know now how to databind to lists
I have one main array which is the returned data from a MySQL query
I have WPF Application where I have One main form and other user controls
We are installing out program via inno setup. We have one main exe file,
I have a one main Workflow which calls several activities asynchronously. Some of the
i have main activity in which i have Four menus. and i have one
I have four different tables, one main SPECIAL table containing only id's that reference
I have read somewhere one of the main differences between Java and C++/C# is

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.