The Path Object

Let's explore the Path Object in detail!

We'll cover the following

The core part of the library is the path object. It contains a pathname - a string that forms the name of the path. The object doesn’t have to point to an existing file in the filesystem. The path might be even in an invalid form.

The path is composed of the following elements:

root-name root-directory relative-path:

  • (optional) root-name: POSIX systems don’t have a root name. On Windows, it’s usually the name of a drive, like "C:"
  • (optional) root-directory: distinguishes relative path from the absolute path
  • relative-path:
    • filename
    • directory separator
    • relative-path

We can illustrate it with the following diagram:

Get hands-on with 1200+ tech skills courses.