You can filter your directories
object inside the for
loop. To quote the docs
When topdown is True, the caller can modify the dirnames list in-place (perhaps using del or slice assignment), and walk() will only recurse into the subdirectories whose names remain in dirnames; this can be used to prune the search, impose a specific order of visiting, or even to inform walk() about directories the caller creates or renames before it resumes walk() again.
So something like
for root, directories, files in os.walk(directory):
directories[:] = [d for d in directories if d not in ['thumbs']]
for filename in files:
if filename.endswith(extensions):
filepath = os.path.join(root, filename)
file_list.append(filepath)
To ignore other directories, you would add their names to the ['thumbs']
list.