Sorting files

Matt Gerrans mgerrans at mindspring.com
Mon Apr 28 00:29:04 EDT 2003


You can sort them using the optional compare function parameter of sort:

Images.sort( lambda a,b: cmp(os.stat(a)[stat.ST_MTIME],
os.stat(b)[stat.ST_MTIME]) )

(This isn't the most readable, you might want to define a separate compare
function and use that)

> How can I get the listing of files of a particular type in a directory,
> sorted by date? For example, I using the following call to get all the
> JPEG's in a dir:
>
> Images = glob.glob1(MyPath+"\\images", "*.jpg")
>
> I want to do just this, but have them sorted by date. Any ideas?







More information about the Python-list mailing list