From the course: Python Essential Libraries
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Walking a file system - Python Tutorial
From the course: Python Essential Libraries
Walking a file system
- [Instructor] One of the more common scenarios that you will see when working with files and directories involves performing some kind of processing on all of the items within a given directory, including subdirectories, and this can be for a variety of reasons. Perhaps you're searching for a particular file, or a piece of information, or you're performing some kind of batch operation, like converting file formats or renaming items. This process is sometimes called walking a file tree, and the PyFilesystem library makes this process really easy by providing an API specifically for this purpose. So let's go ahead and open up the walking_start file, and let's try a basic example. So here in the example code I have imported the OS file system and I've created a file system object for the current directory. So to iterate over all the files within the directory and all the subdirectory I can use the files function which will…
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.