From the course: Python: Working with Files
Unlock the full course today
Join today to access over 24,900 courses taught by industry experts.
Navigate the file system with os module - Python Tutorial
From the course: Python: Working with Files
Navigate the file system with os module
- [Instructor] Python's built-in OS module has lots of functionality for interacting with the operating system. In this video, we'll use it to navigate through a file system and display some files. To start off, we'll open the script file and the LinkedIn Learning folder. I'll be using Sublime. Then we'll import the OS module with import OS. And we'll set up some boiler plate code. Let's create a function for displaying the current directory that this file is run in. We'll call it display_cwd, which stands for current working directory. The current working directory is the current folder we're working in that's users, author, desktop, LinkedIn learning. To retrieve the current folder path that we're in. We'll write OS and use the getcwd function. We'll save the output in a variable called cwd. Then we'll print it to the console. Let's call this function display_cwd. When we run the program, we'll run it in the…
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
-
-
-
-
-