import os.path
for dirpath, dirnames, filenames in os.walk('.'):
    for filename in [f for f in filenames if f.endswith('.log')]:
        pass
How to get files in a directory, including all subdirectories