-
-
Notifications
You must be signed in to change notification settings - Fork 0
path
This class includes methods that are really helpful when working with strings.
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
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 therel_path
couldn't be extended -
use_closest_match: bool = False
whether to try to correct typos in thesearch_in
path/s
Returns:
- the given
rel_path
as absolute path if it was located in any of the search directories -
None
if therel_path
couldn't be located in any of the search directories
Raises: PathNotFoundError
if the given rel_path
is empty or couldn't be resolved (and raise_error
is true)
When the method tries to locate and extend a relative path, it first searches through the following directories:
- the drive root or the root directory
- the current working directory
- the script directory, where the script is running from
- the user's home directory
- 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"
]
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 torel_path
in the script directory or not (then it points torel_path
in the CWD) -
use_closest_match: bool = False
whether to try to correct typos in thesearch_in
path/s
Returns: the extended path if rel_path
was located and the generated path if it wasn't
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⠀★
-
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