ruchit
Hi,
I want to make GUI to copy/paste image sequence from Maya "workspace/images" directory to another directory. It may be N numbers of sub folder in "workspace/images" folder and may be sub folder will contain N numbers of image sequence. In short in GUI there will be option to select desire image sequence and button to copy/paste selected image sequence. so tell me how can i do this??




#Recursive search
#Query all images (with *.exr format) in workspace/images folder
workSpace = mc.workspace(q=True, rootDirectory=True) + 'images/'
files = [y for x in os.walk(workSpace) for y in glob(os.path.join(x[0], '*.exr'))]




pshipkov
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.
Reply 0 0
ruchit
Thnx much !
Reply 0 0
Reply