os.path.getmtime() and compare with a date type

Junchi Tang junchi.tang at gmail.com
Thu Sep 20 12:47:24 EDT 2007


Thanks, that works perfectly!

On 9/20/07, Anthony Greene <sysfault at gmail.com> wrote:
>
> junchi.tang at gmail.com wrote:
> > Hi,
> > I am new to python and are tryint to write a simple program delete log
> > files that are older than 30 days.
> >
> > So I used os.path.getmtime(filepath) and compare it with a date but it
> > does not compile.
> >
> > threshold_time = datetime.date.today() - datetime.timedelta(days=30)
> > mod_time = os.path.getmtime(file_path)
> >
> > if( mod_time < threshold_time):
> >          #delete file
> >
> > However the interpreter complains at the if line, say "can't comapre
> > datetime.date to int
> >
> > How can I covert one of them to make it work?
> >
> > Thank you!
> >
> >
> You are looking for datetime.datetime.fromtimestamp(mod_time)
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070920/617d2269/attachment.html>


More information about the Python-list mailing list