[Tutor] reading file creation date and xreadlines from a point in the middle of a file

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Mon, 4 Feb 2002 18:37:23 -0800 (PST)


On Mon, 4 Feb 2002, Jim Ragsdale wrote:

> I have looked around and have not found a way (that I could
> understand) to read the creation date of a file. Does anyone know how
> to do it? Not necessary but cross platform would be nice. win32 is the
> target.


There are actually two functions in os.path called getatime() and
getmtime, respectively for "access" and "modification" times:

    http://www.python.org/doc/lib/module-os.path.html

os.path.getmtime() is probably what you're looking for:

###
>>> os.path.getmtime('/var/mail/dyoo')      
1012873750
>>> from time import localtime
>>> localtime(os.path.getmtime('/var/mail/dyoo'))
(2002, 2, 4, 17, 49, 10, 0, 35, 0)
###


I'm not sure if the system maintains a "creation" time flag, as it's sorta
arguable that modification is similar to creation.  Perhaps someone else
may be able to find out about this?



> Another question: I am using xreadlines. How do I start reading at a
> specified line in a file?

xreadlines() might not be an appropriate function because it assumes you
want to read through the file sequentially, one line at a time.  If we
suck up the whole file as a list of lines by using readlines(), we can
grab any line by doing an array index, so readlines() is probably a better
choice.


I've written a quicky RandomFile class that I think might be more
memory-efficient if you're concerned about memory usage:

    http://aspn.activestate.com/ASPN/Mail/Message/989629


Good luck to you!