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 - 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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
Understand the file system3m 26s
-
(Locked)
Navigate the file system with os module4m 55s
-
(Locked)
Use os module to uncover path and file details5m 24s
-
(Locked)
Filter path names with glob module3m 53s
-
(Locked)
Recursively list all files in a directory4m 23s
-
(Locked)
Understand Python's new pathlib module3m 42s
-
(Locked)
Create directories in Python3m 20s
-
(Locked)
Solution: Count the number of files2m 16s
-
-
-
-
-