go_from_altered_cwd
- pyhelpers.dirs.go_from_altered_cwd(dir_name, **kwargs)
Get the full pathname of an altered working directory.
- Parameters
dir_name (str or os.PathLike[str] or bytes or os.Path[bytes]) – name of a directory
kwargs – [optional] parameters of the function
pyhelpers.dir.cd()
- Returns
full pathname of an altered working directory (changed from the directory
dir_name
)- Return type
str
Examples:
>>> from pyhelpers.dirs import go_from_altered_cwd >>> import os >>> init_cwd = os.getcwd() >>> init_cwd '<cwd>' >>> # Change the current working directory to "/new_cwd" >>> new_cwd = "\new_cwd" >>> os.mkdir(new_cwd) >>> os.chdir(new_cwd) >>> # Get the full path to a folder named "tests" >>> path_to_tests = go_from_altered_cwd(dir_name="tests") >>> path_to_tests '<new_cwd>\tests' >>> # Get the full path to a directory one level above the current working directory >>> path_to_tests_ = go_from_altered_cwd(dir_name="\tests") >>> path_to_tests_ == os.path.join(os.path.dirname(os.getcwd()), "tests") True >>> os.chdir(init_cwd) >>> os.rmdir(new_cwd)