Navigation

This module offers classes representing filesystem paths with semantics
appropriate for different operating systems. Path classes are divided
between pure paths, which provide purely computational
operations without I/O, and concrete paths, which
inherit from pure paths but also provide I/O operations.

If you’ve never used this module before or just aren’t sure which class is
right for your task, Path is most likely what you need. It instantiates
a concrete path for the platform the code is running on.

Pure paths are useful in some special cases; for example:

If you want to manipulate Windows paths on a Unix machine (or vice versa).
You cannot instantiate a WindowsPath when running on Unix, but you
can instantiate PureWindowsPath.

You want to make sure that your code only manipulates paths without actually
accessing the OS. In this case, instantiating one of the pure classes may be
useful since those simply don’t have any OS-accessing operations.

Note

This module has been included in the standard library on a
provisional basis. Backwards incompatible
changes (up to and including removal of the package) may occur if deemed
necessary by the core developers.

Concrete paths are subclasses of the pure path classes. In addition to
operations provided by the latter, they also provide methods to do system
calls on path objects. There are three ways to instantiate concrete paths:

Create a new directory at this given path. If mode is given, it is
combined with the process’ umask value to determine the file mode
and access flags. If the path already exists, FileExistsError
is raised.

If parents is true, any missing parents of this path are created
as needed; they are created with the default permissions without taking
mode into account (mimicking the POSIX mkdir-p command).

Create a file at this given path. If mode is given, it is combined
with the process’ umask value to determine the file mode and access
flags. If the file already exists, the function succeeds if exist_ok
is true (and its modification time is updated to the current time),
otherwise FileExistsError is raised.