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 48091

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:13:32+00:00 2026-05-10T16:13:32+00:00

In Java you can do File.listFiles() and receive all of the files in a

  • 0

In Java you can do File.listFiles() and receive all of the files in a directory. You can then easily recurse through directory trees.

Is there an analogous way to do this in Python?

  • 0 0 Answers
  • 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. 2026-05-10T16:13:33+00:00Added an answer on May 10, 2026 at 4:13 pm

    Yes, there is. The Python way is even better.

    There are three possibilities:

    1) Like File.listFiles():

    Python has the function os.listdir(path). It works like the Java method.

    2) pathname pattern expansion with glob:

    The module glob contains functions to list files on the file system using Unix shell like pattern, e.g.

     files = glob.glob('/usr/joe/*.gif') 

    3) File Traversal with walk:

    Really nice is the os.walk function of Python.

    The walk method returns a generation function that recursively list all directories and files below a given starting path.

    An Example:

     import os from os.path import join for root, dirs, files in os.walk('/usr'):    print 'Current directory', root    print 'Sub directories', dirs    print 'Files', files 

    You can even on the fly remove directories from ‘dirs’ to avoid walking to that dir: if ‘joe’ in dirs: dirs.remove(‘joe’) to avoid walking into directories called ‘joe’.

    listdir and walk are documented here. glob is documented here.

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

Sidebar

Ask A Question

Stats

  • Questions 76k
  • Answers 77k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer That error message maps to SQLITE_MISUSE (the source code is… May 11, 2026 at 3:15 pm
  • added an answer Add this before your for loop: IFS=' ' Or in… May 11, 2026 at 3:15 pm
  • added an answer Could anyone please tell me where I am going wrong.… May 11, 2026 at 3:15 pm

Related Questions

In Java you can read a file embedded inside a JAR-file by using the
If you had to choose your Favorite (clever) techniques for defensive coding, what would
In java <1.5, constants would be implemented like this public class MyClass { public
I'm working on a web application. There is one place where the user can

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.