From the course: Python: Working with Files

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Recursively list all files in a directory

Recursively list all files in a directory - Python Tutorial

From the course: Python: Working with Files

Recursively list all files in a directory

- [Instructor] To automate file operations, it's important to be able to iterate through different parts of your file system. In the last video, we saw one way to iterate through the sub-directories of a given folder with the glob module. Here, we'll see how to walk through the different paths in your file system using the OS module. The OS module has a function called Walk that can be used to generate the file names in a directory tree. We can walk top down or bottom up. For example, let's say we wanted to walk this current working directory. This directory has two folders. When we walk through the tree in a top-down format, the current folder will be first, and then it will return the sub-directories along with their contents. The current folder acts as a route of sorts and is at the top, and the sub-directories are returned second at the bottom. For a bottom-up walk, the function will return the files at finds…

Contents