is_dir_path¶
- pyhelpers.dirs.is_dir_path(dir_path)[source]¶
Check whether a string is formatted as a directory path.
This function performs a syntax-only check: it does not verify that the directory actually exists, only that the string is shaped like a directory path and does not contain characters or a length that the operating system would reject outright. See also this discussion on Stack Overflow and the Windows System Error Codes reference.
- Parameters:
dir_path (str | bytes | pathlib.Path | os.PathLike) – Pathname of a directory.
- Returns:
Trueifdir_pathis formatted as a valid directory path,Falseotherwise.- Return type:
bool
Examples:
>>> from pyhelpers.dirs import cd, is_dir_path >>> is_dir_path("tests") False >>> is_dir_path("/tests") True >>> is_dir_path(cd("tests")) True >>> is_dir_path(".\tests/") True