小编tse*_*ine的帖子

用于目录搜索的 Python rglob 模式

我尝试在Windows10上使用Python3脚本获取子目录的名称。于是,我写了如下代码:

from pathlib2 import Path
p = "./path/to/target/dir"
[str(item) for item in Path(p).rglob(".")]
# obtained only subdirectories path names including target directory itself.
Run Code Online (Sandbox Code Playgroud)

得到这个结果对我来说很好,但我不知道为什么 rglob 参数的模式返回这个结果。

有人可以解释一下吗?

谢谢。

python python-3.x pathlib

9
推荐指数
1
解决办法
3万
查看次数

标签 统计

pathlib ×1

python ×1

python-3.x ×1