get_relative_path
- pyhelpers.ops.get_relative_path(pathname)[source]
Get the relative or absolute path of
pathname
to the current working directory.- Parameters:
pathname (str | os.PathLike[str]) – pathname (of a file or a directory)
- Returns:
the relative or absolute path of
path_to_file
to the current working directory- Return type:
str | os.PathLike[str]
Examples:
>>> from pyhelpers.ops import get_relative_path >>> import os >>> rel_pathname = get_relative_path(pathname="") >>> rel_pathname '' >>> rel_pathname = get_relative_path(pathname=os.path.join(os.getcwd(), "tests")) >>> rel_pathname 'tests' >>> # On Windows OS >>> rel_pathname = get_relative_path(pathname="C:/Windows") >>> rel_pathname "C:/Windows"