ostk.core.filesystem.Path

class Path

Bases: pybind11_object

Methods

current

Get the current working directory path.

get_absolute_path

Get an absolute version of the Path.

get_last_element

Get the last element (filename or directory name) of the path.

get_normalized_path

Get a normalized version of the Path.

get_parent_path

Get the parent path.

is_absolute

Check if the Path is absolute.

is_defined

Check if the Path is defined.

is_relative

Check if the Path is relative.

parse

Parse a string as a Path.

root

Get the root path of the filesystem.

to_string

Convert the Path to a string representation.

undefined

Create an undefined Path.

__add__(
self: ostk.core.filesystem.Path,
arg0: ostk.core.filesystem.Path,
) ostk.core.filesystem.Path

Concatenate two Paths.

static current() ostk.core.filesystem.Path

Get the current working directory path.

Returns:

The current working directory.

Return type:

Path

Example

>>> current = Path.current()
>>> print(current)  # Current working directory
get_absolute_path(
self: ostk.core.filesystem.Path,
base_path: ostk.core.filesystem.Path = Path.current(),
) ostk.core.filesystem.Path

Get an absolute version of the Path.

Parameters:

base_path (Path, optional) -- The base path to resolve against. Defaults to current directory.

Returns:

The absolute path.

Return type:

Path

Example

>>> relative_path = Path.parse("documents/file.txt")
>>> absolute = relative_path.get_absolute_path()
get_last_element(self: ostk.core.filesystem.Path) ostk.core.type.String

Get the last element (filename or directory name) of the path.

Returns:

The last component of the path.

Return type:

str

Example

>>> path = Path.parse("/home/user/document.txt")
>>> path.get_last_element()  # "document.txt"
get_normalized_path(self: ostk.core.filesystem.Path) ostk.core.filesystem.Path

Get a normalized version of the Path.

Resolves "." and ".." components and removes redundant separators.

Returns:

The normalized path.

Return type:

Path

Example

>>> path = Path.parse("/home/user/../user/./documents")
>>> normalized = path.get_normalized_path()
>>> str(normalized)  # "/home/user/documents"
get_parent_path(self: ostk.core.filesystem.Path) ostk.core.filesystem.Path

Get the parent path.

Returns:

The parent path.

Return type:

Path

Example

>>> path = Path.parse("/home/user/documents")
>>> parent = path.get_parent_path()
>>> str(parent)  # "/home/user"
is_absolute(self: ostk.core.filesystem.Path) bool

Check if the Path is absolute.

Returns:

True if the path is absolute (starts from root), False otherwise.

Return type:

bool

Example

>>> Path.parse("/home/user").is_absolute()  # True
>>> Path.parse("user/documents").is_absolute()  # False
is_defined(self: ostk.core.filesystem.Path) bool

Check if the Path is defined.

Returns:

True if the Path is defined, False otherwise.

Return type:

bool

Example

>>> path = Path.parse("/home/user")
>>> path.is_defined()  # True
is_relative(self: ostk.core.filesystem.Path) bool

Check if the Path is relative.

Returns:

True if the path is relative, False otherwise.

Return type:

bool

Example

>>> Path.parse("user/documents").is_relative()  # True
>>> Path.parse("/home/user").is_relative()  # False
static parse(path_string: ostk.core.type.String) ostk.core.filesystem.Path

Parse a string as a Path.

Parameters:

path_string (str) -- The path string to parse.

Returns:

The parsed Path object.

Return type:

Path

Example

>>> path = Path.parse("/home/user/documents")
>>> path = Path.parse("relative/path")
static root() ostk.core.filesystem.Path

Get the root path of the filesystem.

Returns:

The root path ("/" on Unix systems).

Return type:

Path

Example

>>> root = Path.root()
>>> str(root)  # "/"
to_string(self: ostk.core.filesystem.Path) ostk.core.type.String

Convert the Path to a string representation.

Returns:

String representation of the path.

Return type:

str

Example

>>> path = Path.parse("/home/user")
>>> path.to_string()  # "/home/user"
static undefined() ostk.core.filesystem.Path

Create an undefined Path.

Returns:

An undefined Path object.

Return type:

Path

Example

>>> undefined_path = Path.undefined()
>>> undefined_path.is_defined()  # False