ostk.core.filesystem.Path¶
- class Path¶
Bases:
pybind11_objectMethods
Get the current working directory path.
Get an absolute version of the Path.
Get the last element (filename or directory name) of the path.
Get a normalized version of the Path.
Get the parent path.
Check if the Path is absolute.
Check if the Path is defined.
Check if the Path is relative.
Parse a string as a Path.
Get the root path of the filesystem.
Convert the Path to a string representation.
Create an undefined Path.
- __add__(
- self: ostk.core.filesystem.Path,
- arg0: 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:
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(),
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
Example
>>> undefined_path = Path.undefined() >>> undefined_path.is_defined() # False