A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2005-September/336959.html below:

Chronological Processing of Files

Chronological Processing of Files Chronological Processing of FilesJeremy 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

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4