Sorting files

Zipper114 machowsk1 at attbi.com
Sun Apr 27 20:27:08 EDT 2003


Yup, that was basically it. I changed the "stat.ST_CTIME" to "stat.ST_MTIME"
to get the behaviour I wanted, but that was it. Thanks!


"Nicola Paolucci" <durdn at yahoo.it.oops!.invalid> wrote in message
news:Y7_qa.934482$sj7.37993441 at Flipper...
> Hi Zipper,
>
> Zipper114 wrote:
> > I'm a bit of a noob when it comes to Python, so this might seem a bit
> > trivial, but.....
> >
> > 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?
>
> You could use the os.stat function and the stat module like:
>
> import os
> import pprint
> import stat
>
> p = 'f:/mp3/italiane/Franco Battiato'
> tosort = []
>
> for f in os.listdir(p):
>      tosort.append((os.stat(os.path.join(p,f))[stat.ST_CTIME],f))
>
> tosort.sort()
> pprint.pprint([r[1] for r in tosort])
>
>
> I hope this helps,
> ciao,
> Nick
>
> -- 
> #Remove .oops!.invalid to email or feed to Python:
> 'Tmljb2xhIFBhb2x1Y2NpIDxuaWNrQG5vdGp1c3RjYy5jb20+'.decode('base64')
>






More information about the Python-list mailing list