from pathlib import Path
‘‘‘得到当前目录的绝对路径‘‘‘
Path.cwd()
‘‘‘得到一个目录的绝对路径‘‘‘
a = Path(../XXX/XX)
a.resolve() ‘‘‘列出子目录‘‘‘ p = Path(‘.‘) [x for x in p.iterdir() if x.is_dir()] ‘‘‘在此目录树中列出 Python 源文件‘‘‘ list(p.glob(‘**/*.py‘)) ‘‘‘在目录树中导航‘‘‘ p = Path(‘/etc‘) q = p / ‘init.d‘ / ‘reboot‘ ‘‘‘查询路径是否存在‘‘‘ q.exists() ‘‘‘是否为目录‘‘‘ q.is_dir()
原文:https://www.cnblogs.com/Pio-GD/p/14306750.html