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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:56:40+00:00 2026-05-20T01:56:40+00:00

From what I’ve read around the interwebs and here on SO, os.walk is one

  • 0

From what I’ve read around the interwebs and here on SO, os.walk is one of the best bets for finding all subdirs and files in a directory, but the question I have is, if I only want to recursively find all the subdirectories, is os.walk the fastest solution?

I suppose in addition my question is since the call to os.walk involves for root, dirs, files in os.walk(path), does os.walk actually look at all the files if you don’t necessarily call for it?

Presently, my code is:

for root, dirs, files in os.walk(path):
    for x in dirs:
        DoStuffHere

But it sure seems slow on a folder with many many subdirs and files.

Thanks.

  • 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-05-20T01:56:40+00:00Added an answer on May 20, 2026 at 1:56 am

    I’m not 100% for certain on all aspects of this but from my understanding:

    In general the file listing is already included in the directory metadata so when you look up a directory the data is already there (Linux, not sure bout windows). So this means that os.walk is probably the fastest/simplest way of doing this.

    Also again without profiling do you know if os.walk is really where the slow down is? Remember the general advice is to code up your application/project and then if its too slow, start profiling to find the slow part and re-factor them, etc…

    On os.walk I’m able to os.walk roughly over a few thousand directory + 70 thousand files within a few second so its going to probably be plenty fast for your need.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From what I have read on the web, one of the most efficient algorithms
From here: https://stackoverflow.com/a/2485177/462608 For thread-safe accesses to shared data, we need a guarantee that
From an alphanumeric string I need to pick all two digit numbers. e.g.: input
From what I have read, it is impossible to send a cookie across domains,
From here: http://www.codingwithoutcomments.com/ If you do use Singletons, try to use dependency injection instead
From the paper of bigtable. bigtable I read this: Each METADATA row stores approximately
From your experience, are there any security measures that one should undertake on a
From reading a few questions and answers here, it seems that a telnet stream
From an efficiency and best practices point of view, I appreciate everyones thoughts. I
I have a text area in my form which accepts all possible characters from

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.