I have a working function that generates a list from directories of images
def jpg_descended(folder):
matches = []
for root, dirnames, filenames in os.walk(unicode(folder)):
for extension in ('*.jpg', '*.jpeg', '*.png'):
for filename in fnmatch.filter(filenames, extension):
matches.append(os.path.join(root, filename))
return sorted(matches, key=os.path.getmtime, reverse=True)
but how can I get it to skip over directories I've put in a list?
excludes = ["october", "december"]
I want it to NOT return anything in directories named "october" or "december" or any other directories I may add to the excludes list.
Any and all help is appreciated.
You can edit
dirnames
in place by deleting directories that meet your requirements. whentopdown=True
(the default) foros.walk
, that prevents those directories from being enumerated.Make sure it is an in place edit, for example: