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:
The class implements a lot of methods that extracts the parts of the path:
Method | Description |
---|---|
path::root_name() |
returns the root-name of the path |
path::root_directory() |
returns the root directory of the path |
path::root_path() |
returns the root path of the path |
path::relative_path() |
returns path |