format_display_path¶
- pyhelpers.dirs.format_display_path(path, normalized=True, surrounded_by='"', is_dir=None, prepend_dot=False)[source]¶
Format a path string for display, logging or printing purposes.
This function generates a visual representation of a path. It can optionally add trailing slashes for directories, wrap the output in quotes and prepend a dot-slash for relative paths (e.g. when preparing shell commands).
- Parameters:
path (str | bytes | pathlib.Path | os.PathLike) – The filesystem path to format for display.
normalized (bool) – Whether to standardize slashes via
_normalize_path(). Defaults toTrue.surrounded_by (str) – A string literal used to wrap the output. Defaults to
'"'.is_dir (bool | None) – Explicitly treat the path as a directory. If
None, the filesystem is checked first; when the path does not exist, this falls back to a heuristic that treats a path without a file extension as a directory (which can misclassify extensionless files such as"Makefile"or"LICENSE"). Defaults toNone.prepend_dot (bool) – If
True, prepends a./(or native OS equivalent) to paths that are not absolute. Defaults toFalse.
- Returns:
Formatted pathname with configured slashes and wrappers.
- Return type:
str
Examples:
>>> from pyhelpers.dirs import format_display_path >>> format_display_path("pyhelpers\data") '"pyhelpers/data/"' >>> format_display_path("pyhelpers\data", normalized=False) # on Windows '"pyhelpers\data\"' >>> format_display_path("pyhelpers\data\pyhelpers.dat", prepend_dot=True) '"./pyhelpers/data/pyhelpers.dat"' >>> format_display_path("C:\Windows", prepend_dot=True) # on Windows '"C:/Windows/"'