os.path and related functions

Python provides several methods to work with filesystem and directory paths

os.path

The os.path sub-module of the os module has lots of great functionality built into it. We’ll be looking at the following functions:

  • basename
  • dirname
  • exists
  • isdir and isfile
  • join
  • split

There are lots of other functions in this sub-module. You are welcome to go read about them in the Python documentation, section 10.1.

os.path.basename

The basename function will return just the filename of a path. Here is an example:

Get hands-on with 1400+ tech skills courses.