From the course: Python: Working with Files
Unlock the full course today
Join today to access over 24,000 courses taught by industry experts.
Understand Python's new pathlib module - Python Tutorial
From the course: Python: Working with Files
Understand Python's new pathlib module
- [Instructor] Traditionally, Python has represented file paths using regular text strings. Paths have lots of information and in order to retrieve that information, important functionality is spread all around the standard library, including in the OS, glob and shutil modules. The pathlib module was introduced in Python 3.4 and it presents an alternative way of representing directory and file paths. It represents them as objects instead of strings. To use it, we can import path from the pathlib module. Let's print this directory's contents. To access the current directory, we can use the cwd function on the Path module. This object is either a POSIX path or a Windows path object, depending on the operating system. With the entries, we can iterate through each entry and print out specific attributes. Entries.iterdir creates an iterator of all the files and folders in the current working directory. Each entry contains…
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
-
-
-
-
-