The built-in Python
pathlib module provides clean and intuitive functionality for working with the filesystem.
Here, I'm showing a few common use-cases of
pathlib. Firstly, the main class containing the
pathlib functionality is
Path. You can define an instance of a
Path by instantiating it with a string representation of the path of interest (line #4). One great feature of
Path is that it will automatically handle the idiosyncrasies of the operating system, so in general, code that is written with the Windows filesystem in mind (for example) can be easily ported to other operating systems, and vice-versa.