I'm using os.walk
and fnmatch
with filters to search a pc's hdd for all image files. This works perfectly fine but is extremely slow since it takes about 9 minutes to search +-70000 images.
Any ideas on optimizing this code to run faster? Any other suggestions?
I'm using python 2.7.2 by the way.
import fnmatch
import os
images = ['*.jpg', '*.jpeg', '*.png', '*.tif', '*.tiff']
matches = []
for root, dirnames, filenames in os.walk("C:\\"):
for extension in images:
for filename in fnmatch.filter(filenames, extension):
matches.append(os.path.join(root, filename))