Use Python os.walk to identify a list of files [duplicate]

Try something like this:

def fileList(source):
    matches = []
    for root, dirnames, filenames in os.walk(source):
        for filename in filenames:
            if filename.endswith(('.mov', '.MOV', '.avi', '.mpg')):
                matches.append(os.path.join(root, filename))
    return matches

Leave a Comment