Get age of a file/dir
url81-1
earle.ady at gmail.com
Tue Aug 1 20:23:41 EDT 2006
Actually this has nothing to do with datetime.datetime -- he's asking
how to find the created time of the directory.
Python has a builtin module called "stat" (afer sys/stat.h) which
includes ST_ATIME, ST_MTIME, ST_CTIME members which are times accessed,
modified, and created, respectively.
Best,
Earle Ady
Jim wrote:
> Carl J. Van Arsdall wrote:
> > I've been looking around the OS module and I haven't found anything
> > useful yet. Does anyone know how to get the age of a file or directory
> > in days? I'm using unix and don't seem to find anything that will help
> > me. The only function that comes close so far is
> >
> > os.path.getctime(path)
> >
> >
> > However this only gets creation time on Windows, on Unix it gets the the
> > time of the last change. Any ideas?
> >
> > Thanks!
> >
> > -carl
> >
> > --
> >
> > Carl J. Van Arsdall
> > cvanarsdall at mvista.com
> > Build and Release
> > MontaVista Software
>
> Hi,
> You should check out the datetime module. And convert dates to an
> ordinal number.
> today = datetime.date.today().toordinal()
> age = today - datetime.date(year, month, day).toordinal()
> Jim
More information about the Python-list
mailing list