自行实现 from pathlib import Path def walk(dir="./data"): root=Path(dir) assert(root.is_dir()) lst=[root] while len(lst): d=lst.pop(0) for p in d.iterdir(): if p.is_dir(): lst.append(p) elif p.is_file(): yield p for p in walk(): print(p) 官方方法 for p in Path("./data/").glob("**/*"): print(p)