krystosan 0 Junior Poster

just wrote a snippet that return true if whole image sequnce exist else returns false,

import os

def sequenceExists(seqPath,firstFrame,lastFrame,sep=None):

    """ Checks if sequence exist on disk.
           seqPath = image sequence path
               example: J:/Footages/33x01_02a/33x01_02a.%04d.sgi
               where %04d can be any number like 0001, 231 but not KFd001 string
               change buildPath at line 20 to customize for compatibility
           frstFrame = First frame as string
           lastFrame = Last frame as string
    """
    builPath = ""
    fnSep = sep or "."

    seqPathLst = seqPath.split(fnSep)
    frmNumLen = len(firstFrame)
    for each in range(int(firstFrame),int(lastFrame)+1):
        newLen = frmNumLen - len(str(each))
        numFmt =  newLen* "0" + str(each)
        buildPath = seqPathLst[0] + fnSep + numFmt + fnSep + seqPathLst[-1]
        if not os.path.exists(buildPath):
            return False
    return True

please point mistakes or better way of achieving this task ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.