validate_dir
- pyhelpers.dirs.validate_dir(path_to_dir=None, subdir='', msg='Invalid input!', **kwargs)
Validate the pathname of a directory.
- Parameters
path_to_dir (str or os.PathLike[str] or bytes or os.Path[bytes] or None) – pathname of a data directory, defaults to
None
subdir (str or os.PathLike[str] or bytes or os.Path[bytes]) – name of a subdirectory to be examined if
directory=None
, defaults to""
msg (str) – error message if
data_dir
is not a full pathname, defaults to"Invalid input!"
kwargs – [optional] parameters of the function
pyhelpers.dir.cd()
- Returns
valid full pathname of a directory
- Return type
str
Examples:
>>> from pyhelpers.dirs import validate_dir >>> import os >>> dat_dir = validate_dir() >>> os.path.relpath(dat_dir) '.' >>> dat_dir = validate_dir("tests") >>> os.path.relpath(dat_dir) 'tests' >>> dat_dir = validate_dir(subdir="data") >>> os.path.relpath(dat_dir) 'data'