Path Expansion¶
Conversion between pathnames with and without expanded %ENVIRONMENT_VARIABLES%.
- mhi.common.path.expand_path(path: str, abspath: bool = False, folder: str = None) str ¶
Expand
path
, by replacing a ~ or ~user prefix, as well as expanding any $var, ${var} and %var% patterns in the path.- Parameters:
path (str) – The path to be expanded.
abspath (bool) – If True, convert resulting path to an absolute path.
folder (str) – If provided, the path to the filename is resolved relative to this folder.
- Returns:
The expanded
path
, optionally forced to an absolute path.- Return type:
str
- mhi.common.path.expand_paths(paths: Sequence[str], abspath: bool = False, folder: str = None) List[str] ¶
Expand
paths
, by replacing a ~ or ~user prefix, as well as expanding any $var, ${var} and %var% patterns in the paths.- Parameters:
path (List[str]) – A list of paths to be expanded.
abspath (bool) – If True, convert resulting paths to absolute paths.
folder (str) – If provided, the paths to the filenames are resolved relative to this folder.
- Returns:
A list of expanded
paths
, optionally forced to absolute paths.- Return type:
List[str]
- mhi.common.path.contract_path(path)¶
Look for and replace any substring of the path that matches a value found in an environment variable with that environment variable: ${key} or %key%. Additionally, replace a path starting with the user’s home path with ~.
- Parameters:
path (str) – The path to be shortened by replacing parts with environment variables.
- Returns:
The contracted
path
.- Return type:
str
- mhi.common.path.contract_paths(paths)¶
Look for and replace any substring of the paths that matches a value found in an environment variable with that environment variable: ${key} or %key%. Additionally, replace paths starting with the user’s home path with ~.
- Parameters:
paths (List[str]) – The paths to be shortened by replacing parts with environment variables.
- Returns:
A list of contracted
paths
.- Return type:
List[str]
- mhi.common.path.shell_folder(name: str) Path ¶
Return the path to a special Windows Shell Folder
- Parameters:
name (str) – The shell folder name
- Returns:
The path, read from the Windows registry
- Return type:
str