Possible Duplicate:
In Python, fastest way to build a list of files in a directory with a certain extension
I currently am using os.walk to recursively scan through a directory identifying .MOV files
def fileList():
matches = []
for root, dirnames, filenames in os.walk(source):
for filename in fnmatch.filter(filenames, '*.mov'):
matches.append(os.path.join(root, filename))
return matches
How can I extend this to identify multiple files, e.g., .mov, .MOV, .avi, .mpg?
Thanks.
Try something like this:
def fileList(source):
matches = []
for root, dirnames, filenames in os.walk(source):
for filename in filenames:
if filename.endswith(('.mov', '.MOV', '.avi', '.mpg')):
matches.append(os.path.join(root, filename))
return matches
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With