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

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…

Contents