Listing All Files in a Directory With Python

Alexandra Davis
Alexandra Davis 9 Lessons 28m intermediate

Getting a list of all the files and folders in a directory is a natural first step for many file-related operations in Python. When looking into it, though, you may be surprised to find various ways to go about it.

When you’re faced with many ways of doing something, it can be a good indication that there’s no one-size-fits-all solution to your problems. Most likely, every solution will have its own advantages and trade-offs. This is the case when it comes to getting a list of the contents of a directory in Python.

In this video course, you’ll be focusing on the most general-purpose techniques in the pathlib module to list items in a directory, but you’ll also learn a bit about some alternative tools.

What’s Included:

Downloadable Resources:

About Alexandra Davis

Alexandra is an avid Pythonista and course instructor at Real Python based in Arizona. She is a software engineer with a passion for full stack web development and Python.

» More about Alexandra

Each tutorial at Real Python is created by a team of developers so that it meets our high quality standards. The team members who worked on this tutorial are:

« Browse All Courses