Recursively iterate through all subdirectories using pathlib

前端 未结 5 1302
清酒与你
清酒与你 2020-12-01 15:36

How can I use pathlib to recursively iterate over all subdirectories of a given directory?

p = Path(\'docs\')
for child in p.iterdir(): child
5条回答
  •  长情又很酷
    2020-12-01 16:09

    You can use the glob method of a Path object:

    p = Path('docs')
    for i in p.glob('**/*'):
         print(i.name)
    

提交回复
热议问题