Introduction to the Python Pathlib Module

python_tutorials

The Pathlib module in Python simplifies the way in working with files and folders. The Pathlib module is available from Python 3.4 and higher versions. It combines the best of Python’s file system modules namely os, os.path, glob, etc.

In Python, most of the scripts involve interacting with file systems. Hence, it is important to deal with file names and paths. To achieve this, Python includes the Pathlib module which contains useful functions to perform file-related tasks. Pathlib provides a more readable and easier way to build up paths by representing filesystem paths as proper objects and enables us to write code that is portable across platforms.

In this article, we will study the Pathlib module in detail with the help of various examples.

The Concept of Path and Directory

Before moving further into details of the Pathlib module, it’s important to understand 2 different concepts namely – path and directory.

The path is used to identify a file. The path provides an optional sequence of directory names terminated by the final file name including the filename extension. The filename extension provides some information about the file format/ contents.

To finish reading, please visit source site