Process files in order

Yu-Xi Lim yuxi at ece.gatech.edu
Thu Jul 27 16:38:02 EDT 2006


Khoa Nguyen wrote:
> I have a requirement to process all files in a directory in
> chronological order. The os.listdir() function, however, lists the
> files in random order. Is there a similar function in Python that
> allows me to specify the listing order (like ls -t for example)?

There is no single command, but you can easily sort the results of
listdir using any criteria. Most file attributes can can be obtained
using os.stat (size, creation date, modification date, etc), and you can
just use that as a key to sort().



More information about the Python-list mailing list