Recursively iterate through all subdirectories using pathlib

前端 未结 5 1305
清酒与你
清酒与你 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-01 15:59

    pathlib has glob method where we can provide pattern as an argument.

    For example : Path('abc').glob('**/*.txt') - It will look for current folder abc and all other subdirectories recursively to locate all txt files.

提交回复
热议问题