I use os.walk
and fnmatch
with filters to search pc hdd for all image files. This works fine, but very slow, since it takes about 9 minutes to search for + -70,000 images.
Any ideas on optimizing this code to work faster? Any other suggestions?
I am 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))
source share