File and Directory Management in Python: 10 Essential Operations

Python developers don’t need to open their file explorers

Yang Zhou
TechToFreedom

--

Python is one of the best programming languages to automate the boring stuff about system management. For example, if you maintain a website and need to remove some out-of-date log files on some directories every day. How to do it?

A non-programmer will remove these useless files one by one.

A Linux guru will write a Shell script and schedule a task.

A Python developer, even if he doesn’t know anything about Shell scripts, can also automate the task with Python. After all, when it comes to file and directory management, Python can do everything that Linux Shell or Windows PowerShell scripts do.

This article will dive into the 10 most common operations about file and directory management in Python. After reading, you probably don’t need to open your file explorer again. Or you don’t even need a graphical user interface (GUI) to handle your computer. After all, cool hackers in films never use GUI. 😄

1. Print Current Working Directory

Before we do something on our system, the first information we need to know is where we are. In Python, we can easily get the current…

--

--