Chronological Processing of Files
Jeremy Jones
zanesdad at bellsouth.net
Wed Sep 21 19:48:00 EDT 2005
yoda wrote:
>This feels like a stupid question but I'll ask it anyway.
>
>
Definitely not a stupid question.
>How can I process files chronologically (newest last) when using
>os.walk()?
>
>
>
Try this:
In [16]: file_list = [(os.stat(f)[8], f) for f in [os.path.join(i[0],
j) for i in os.walk("/home/jmjones/public_html") for j in i[2]]]
In [17]: file_list.sort()
In [18]: sorted_file_list = [f[1] for f in file_list]
I *think* os.stat()[8] is the modification time element...but this
should probably work for you. That first list comprehension looks like
a booger if you're not familiar with them. If you have any trouble with
it, just shoot a message back to the list and I'll decypher it for you.
- JMJ
More information about the Python-list
mailing list