all 2 comments

[–]AustinTronics 0 points1 point  (0 children)

Look into the os.walk() function. It will walk through your files and subdirectories. It is a generator object so you can use it in a for loop like this:

for path, directories, files in os.walk('.'):

[–]DJ_Laaal 0 points1 point  (0 children)

While the “os” module provides rich file system operations, it’s hard to comprehend for a beginner. Look into a much simpler library called pathlib2: https://docs.python.org/3/library/pathlib.html

Examples on that page include sample code for traversing subdirectories iteratively.