Issue
How can I use pathlib
to recursively iterate over all subdirectories of a given directory?
p = Path('docs')
for child in p.iterdir():
# do things with child
only seems to iterate over the immediate children of a given directory.
I know this is possible with os.walk()
or glob
, but I want to use pathlib because I like working with the path objects.
Solution
You can use the glob
method of a Path
object:
p = Path('docs')
for i in p.glob('**/*'):
print(i.name)
Answered By - Jacques Gaudin
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.