Friday 29 April 2016

Get recursive file listing in python

Below is the python code:

def get_recursive_filelist(rootdir):
    outfiles = []
    if os.path.isfile(rootdir):
        outfiles.append(rootdir)
    for (dir, _, files) in os.walk(rootdir):
        for f in files:
            path = os.path.join(dir, f)
            if os.path.exists(path):
                outfiles.append(path)
    return outfiles

No comments:

Post a Comment