listing files by modification time

Deepak Rokade smartpawn at gmail.com
Tue Feb 17 09:16:07 EST 2009


Yes I can do that but for that I will have to go through entire list of
files and also I will have to first get the whole list of files present in
directory.

In case of my application this list can be huge and so want to list the
files which suits my criteria.
Similar to the unix find command I sent earlier or like below.

find /  -mtime +5 -type f -exec ls  -l {} \;

Otherwise can I limit the number of files in a list returned by os.listdir()
?



On Tue, Feb 17, 2009 at 6:06 PM, Chris Rebert <clp2 at rebertia.com> wrote:

> On Tue, Feb 17, 2009 at 4:31 AM, Deepak Rokade <smartpawn at gmail.com>
> wrote:
> > Hi,
> >
> > I am using python 2.5 on sun solaris.
> >
> > I want to limit the number of files returned by os.listdir() to some
> number
> > (say 1000), how can I do it ?
> >
> > Also I wan to list the files only if they are older than some x days, how
> > can I do it?
>
> You can filter the returned list of files by checking the results of
> os.stat() [http://docs.python.org/library/os.html#os.stat] on the
> files. The `stat` module [http://docs.python.org/library/stat.html]
> can help with the interpretation of the data returned from os.stat().
>
> Cheers,
> Chris
>
> --
> Follow the path of the Iguana...
> http://rebertia.com
>



-- 
Thanx & Regards,
Deepak Rokade

Do what u Enjoy &
               Enjoy what u Do...........
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090217/17de5d3b/attachment-0001.html>


More information about the Python-list mailing list