Programming with Python

⌘K
  1. Home
  2. Docs
  3. Programming with Python
  4. File Handling
  5. The os Module and Common Functions

The os Module and Common Functions

The os module in Python provides functions to interact with the operating system, including file and directory operations.

Thank you for reading this post, don't forget to subscribe!
The os Module and Common Functions

Example: Using the os Module:

import os

# Rename a file
os.rename("example.txt", "new_example.txt")

# Remove a file
os.remove("new_example.txt")

# Create a directory
os.mkdir("NewFolder")

# List files in the current directory
print(os.listdir("."))

# Remove an empty directory
os.rmdir("NewFolder")

How can we help?