Sort files by date
Scott David Daniels
Scott.Daniels at Acm.Org
Wed Jul 13 13:03:08 EDT 2005
Jeremy Sanders wrote:
> fargo wrote:
>
>
>>I'm looking for some way to sort files by date.
>
>
> you could do something like:
>
> l = [(os.stat(i).st_mtime, i) for i in glob.glob('*')]
> l.sort()
> files = [i[1] for i in l]
>
> Jeremy
>
If you have 2.4 or later:
def mtime(filename):
return os.stat(filename).st_mtime
lst = sorted(glob.glob('*'), key=mtime)
--Scott David Daniels
Scott.Daniels at Acm.Org
More information about the Python-list
mailing list