find_dir
(函数来自 pyomo.common.fileutils)
- pyomo.common.fileutils.find_dir(dirname, cwd=True, mode=4, pathlist=[], allow_pathlist_deep_references=True)[source]
定位一个目录,给定一组搜索参数
- Parameters:
dirname (str) – 要定位的目录名称。名称可能包含对用户主目录的引用 (
~user), 环境变量 (${HOME}/bin), 和 shell 通配符 (?和*); 所有这些 都将被扩展。cwd (bool) – 首先在当前工作目录中查找 [默认值: True]
mode (mask) – 如果不为None,则只返回可以读取/写入/执行的目录。有效值是{os.R_OK, os.W_OK, os.X_OK}的包含OR [默认:
os.R_OK]pathlist (str 或 iterable 的 str) – 包含要搜索路径的字符串列表,每个字符串包含一个路径。如果 pathlist 是一个字符串,则首先使用 os.pathsep 进行分割以生成 pathlist [默认值:
[]]。allow_pathlist_deep_references (bool) – 如果 allow_pathlist_deep_references 为 True 并且 dirname 看起来是一个相对路径,则允许相对于 pathlist 中的目录进行深度引用匹配(例如,如果 dirname 是
foo/bar并且/usr/bin在 pathlist 中,那么find_dir()可能会返回/usr/bin/foo/bar)。如果 allow_pathlist_deep_references 为 False 并且 dirname 看起来是一个相对路径,则只允许相对于当前目录的匹配(假设 cwd==True)。[默认值:True]
注释
find_dir 使用 glob,因此路径和/或目录名可能包含通配符。返回第一个匹配的目录。