[Tutor] file modification dates

Michael P. Reilly arcege@shore.net
Sun, 16 Jan 2000 20:40:15 -0500 (EST)


> In that context, how can I discover the creation or modifiation
> date/time of a file? I didn't see anything in the documentation (but
> I've been known to read right over the answer I'm looking for). I'm
> looking for something beyond os.exec(...), and I'm mostly interested in
> Linux (if the solution is platform-dependent), but other platform info
> would be useful as tell.

There are some relatively new functions that are more platform
independant:

Python 1.5.2 (#6, Apr 20 1999, 10:35:35)  [GCC 2.7.2.2] on sunos5
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import os, time
>>> os.path.getsize('.profile')
4998
>>> time.ctime(os.path.getmtime('.profile'))
'Sat Jun 26 10:48:47 1999'
>>>

(There is a getatime() function also, but contains a bug which gets the
mtime instead of the atime).

For the less independant:

>>> statinfo = os.stat('.profile')
>>> statinfo[os.path.stat.ST_SIZE]
4998
>>> time.ctime(statinfo[os.path.stat.ST_MTIME])
'Sat Jun 26 10:48:47 1999'
>>>

There is no "creation" time stored with files on a UNIX system (the
ctime is the "inode change" time of the file on UNIX).

  -Arcege

-- 
------------------------------------------------------------------------
| Michael P. Reilly, Release Engineer | Email: arcege@shore.net        |
| Salem, Mass. USA  01970             |                                |
------------------------------------------------------------------------