Member-only story

The Beginner’s Guide to Managing Directories in Python

Navigate Folders Like a Pro with These Easy Python Commands

Max N
2 min readMar 26, 2024

Whether you’re a seasoned developer or just starting your coding journey, mastering the art of creating and removing directories is a crucial skill. Python offers a user-friendly way to handle these tasks, making it easier for you to organize your projects and keep your file structure tidy.

In this article, we’ll walk through the simple steps to create, remove, and navigate directories using Python.

Creating a New Directory

Creating a new directory in Python is a breeze with the os module. Here's how you do it:

import os

# Creating a new directory
os.mkdir("new_directory")

The os.mkdir() function creates a new directory with the specified name in the current working directory. If you want to create a nested directory, you can use the os.makedirs() function instead:

import os

# Creating a nested directory
os.makedirs("parent_directory/child_directory")

This will create both the parent_directory and the child_directory within it, if they don't already exist.

Removing a Directory

--

--

Max N
Max N

Written by Max N

A writer that writes about JavaScript and Python to beginners. If you find my articles helpful, feel free to follow.

No responses yet