Chronological Processing of Files

Paul Luap777 at hotmail.com
Wed Sep 21 18:25:00 EDT 2005


untested, ugly, but something like this would sort all the files in the
directory on os.path.getctime (not using os.walk() though). I'm sure
there is probably better ways to do it :)

filelist = []

def walkdir(currdir):
    for files in os.listdir(currdir):
        path = os.path.join(currdir, files)
        if not os.path.isdir(path):
            filelist.append([os.path.getctime(path), path])
        else:
            walkdir(path)

walkdir(r'c:\somedirectory')

filelist.sort()

for item in filelist:
    dosomething(item[1])

dosomething is whatever function to process the files




More information about the Python-list mailing list