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

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?

  • 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. 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

Related Questions

I'm looping through a directory in Java, trying to read each of the files.
In Java can I create a URI for a file located locally in the
What is the maximum file size 32 bit java can access? Is this architecture
How can I load a .java file into a CompilationUnit? For example, lets say
How can I get java classes from an xml file? In this situation, I
How can i extract bz2 file in Java on Android? Are any included libraries
in a java webstart file (jnlp) you can specify the nativelib tag to load
How can I delete the content of a file in Java?
Can i write oblects in java into file and retrieve the same?? In c++
How can I embed binary file (executable, to be exact) in Java application? 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.