Skip to content

Python OS

How to Move Files in Python (os, shutil) Cover Image

How to Move Files in Python (os, shutil)

Automating tasks such as moving files or renaming files is an essential skill for any Python developer. Because Python is a general-purpose programming language, it offers many possibilities for working with and automating file workflows. In this tutorial, you’ll learn

How to Rename Files in Python with os.rename() Cover Image

How to Rename Files in Python with os.rename()

Being able to work with files is an essential skill for a Python developer of any skill level. In particular, Python can be used to easily rename a single file or multiple files. Being able to automate repetitive tasks, such

How to Get File Size in Python in Bytes, KB, MB, and GB Cover Image

How to Get File Size in Python in Bytes, KB, MB, and GB

When working with files programmatically, you’ll often want to know how large a file is. This can be helpful when transferring files or copying files. Python provides a number of built-in methods of doing this, including using the os and

Python Create Directory if It Doesn't Exist Cover Image

Python: Create a Directory if it Doesn’t Exist

In this tutorial, you’ll learn how to use Python to create a directory if it doesn’t exist. Creating directories programmatically can save you a ton of time. However, not checking if the directory exists first can lead to significant problems,

Environment Variables in Python Cover Image

Using Environment Variables in Python

In this post, you’ll learn about how to use environment variables in Python on Windows, macOS, and Linux. Environment variables in Python enable you to write smoother workflows and more secure code. You’ll learn why environment variables are useful to

Python Check if File Directory Exists Cover Image

Python: Check if a File or Directory Exists

Learn how to use Python to check if a file or a directory exists, using the pathlib and os libraries, including writing conditional checks.

Python Copy a File Cover Image

Python: Copy a File (4 Different Ways)

Learn how to use Python to copy a file, including 4 different ways to accomplish this. Learn how to copy metadata and permissions.