Skip to content
XulbuX edited this page Sep 15, 2025 · 3 revisions

Path

This class includes methods that are really helpful when working with strings.


Class Properties

A class property can be accessed with Path.<property name>.

cwd the path to the current working directory
script_dir the path to the directory of the current script


extend()

This method tries to resolve and extend a relative path to an absolute path.
Params:

  • rel_path: str the path to be extended
  • search_in: str | list[str] = None one or multiple directories to search the relative path in
  • raise_error: bool = False whether to raise an error if the rel_path couldn't be extended
  • use_closest_match: bool = False whether to try to correct typos in the search_in path/s

Returns:

Raises:PathNotFoundError if the given rel_path is empty or couldn't be resolved (and raise_error is true)

Search in:

When the method tries to locate and extend a relative path, it first searches through the following directories:

  1. the drive root or the root directory
  2. the current working directory
  3. the script directory, where the script is running from
  4. the user's home directory
  5. the system temporary directory

If the rel_path wasn't found in any of those directories, the method will search in the search_in directory/s, which is a single or multiple absolute directory path/s.

Example:

search_in = [
    "C:\\Users\\User\\Documents",
    "C:\\Users\\User\\Desktop",
    "D:\\other\\Path\\to\\Custom\\SearchDirectory"
]

extend_or_make()

This method tries to locate and extend a relative path to an absolute path, and if the relative path couldn't be located, it generates a path, as if it was located.
Params:

  • rel_path: str the path to be extended
  • search_in: Optional[str | list[str]] = None one or multiple directories to search the relative path in
  • prefer_script_dir: bool = True whether to make a path that points to rel_path in the script directory or not (then it points to rel_path in the CWD)
  • use_closest_match: bool = False whether to try to correct typos in the search_in path/s

Returns: the extended path if rel_path was located and the generated path if it wasn't


remove()

This method removes the directory or the directory's content at the specified path.
Params:

  • path: str the path to the directory to be removed/emptied
  • only_content: bool = False whether to remove only the directory's content

Returns:no return value

★⠀Python Library by XulbuX⠀★

Project Links

Testing and Formatting

Classifiers

  • Intended Audience:
    • Developers
  • License:
    • OSI Approved
    • MIT License
  • Operating Systems:
    • Full Library: OS Independent
  • Supported Python Versions:
    • Python 3.13
    • Python 3.12
    • Python 3.11
    • Python 3.10
  • Topics:
    • Libraries
    • Python Modules
    • Software Development

The XulbuX Logo
Clone this wiki locally