Recently i had to do something similar.
# the top directory you will be looking for image sequences under
directory = "/path/to/image/sequences/"
# i crawled the directory structure the "proper" way, but even we talk python here,
# code gets unnecessary complex for little practical gain in this particular case.
# I advise you to just look current level + 3 (or more, if you wish) levels
# down = clean and simple.
# This is not a performance critical task, so a tiny bit of overhead is not a problem.
# Also, if one has more than 3 nested levels, he is probably doing his elements
# management wrong and has to be corrected :)
files = glob.glob(directory+"*.*.*")
files += glob.glob(directory+"*/*.*.*")
files += glob.glob(directory+"*/*/*.*.*")
files += glob.glob(directory+"*/*/*/*.*.*")
extensions = [".exr", ".jpg", ".png", ".iff", ".sgi", ".tga", ".tif"]
sequences = {}
for f in files:
f = f.lower().replace("\\", "/") # take care of windows paths, force lower case
name, ext = os.path.splitext(f)
if ext not in extensions: continue
directory, name = os.path.split(f)
l = name.split(".")
# support for file names with multiple dots in it - like some.file.name.1001.jpg
mask = directory+"/"+".".join(str(s) for s in l[:-1])+".%"+str(len(l[-1])).zfill(2)+"d"+ext
if mask not in sequences.viewkeys(): sequences[mask] = [f]
else: sequences[mask].append(f)
This will give you dictionary with keys looking like this: "/path/to/frames.%04d.jpg"
the values will be lists with the image files.
Typing this directly without testing it, so there may be glitches in the code snippet.