ccd¶
- pyhelpers.dirs.ccd(*subdir, **kwargs)[source]¶
Get the full pathname of a directory (or file) in an altered working directory.
- Parameters:
subdir (str | os.PathLike[str] | bytes | os.PathLike[bytes]) – Name of a directory or file.
kwargs – [optional] Parameters for the function
cd()
.
- Returns:
Pathname of a directory or file in the altered working directory.
- Return type:
str
Examples:
>>> from pyhelpers.dirs import ccd >>> import os >>> init_cwd = os.getcwd() >>> os.path.relpath(init_cwd) '.' >>> # Change the current working directory to "/new_cwd" >>> new_cwd = "tests/new_cwd" >>> os.makedirs(new_cwd, exist_ok=True) >>> os.chdir(new_cwd) >>> # Get the full path to a folder named "tests" >>> path_to_tests = ccd("tests") >>> os.path.relpath(path_to_tests) 'tests' >>> path_to_tests_ = ccd("test1", "test2") >>> path_to_tests_ == os.path.join(os.getcwd(), "test1", "test2") True >>> os.chdir(init_cwd) >>> os.rmdir(new_cwd)