Photo by girlart39 on Pixabay

8 Must-Know File System Operations In Python

The essential for Python in tasks automation apps

In recent years, Python is known by a lot more people who are not programmers. This is not only because of its popularity in the area of Machine Learning but also because it could be used to automate a lot of repetitive works such as bulk editing files with certain patterns.

When the automation tasks are related to files, it is important to master the file system interfaces in Python. In this article, I’ll introduce 8 file system operations in Python that are the most important and essential. Hope it can guide some learners to have an easier start.

All the source code are available in a Google Colab Notebook which has been made public. Please find the link in the last section and try them by yourself!

1. Show Current Directory

The first operation that I want to start with is to show the Current Working Directory (CWD). It is important because we might want to use relative paths in most of the time. Therefore, it is sometimes important to know where we are at the moment.

One of the reasons that the relative path is recommended because it doesn’t create limitations of your application. No matter who copied your application, it should run on their…

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Published in Towards Data Science

Your home for data science and AI. The world’s leading publication for data science, data analytics, data engineering, machine learning, and artificial intelligence professionals.

Written by Christopher Tao

👁️ 4M+ Reads🏆19k+ Followers🥇Top 50 Writer👨‍🎓PhD💻Data & Analytics Leader 🤝LinkedIn https://www.linkedin.com/in/christopher-tao-5717a274/

Responses (5)

What are your thoughts?

Path from pathlib is a better abstraction than os.path. I highly recommend switching.

For all of those curious readers, who don't know where all this good stuff is properly documented:

Guys... Please stop using os.path! Stop recommending it! DO NOT USE IT. Just use pathlib. Your code will be pythonic, cleaner and better. Please!