我尝试在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 参数的模式返回这个结果。
有人可以解释一下吗?
谢谢。