os.utime

Dan Stromberg drsalists at gmail.com
Sun Mar 20 20:40:23 EDT 2011


1) If you want to set the ctime to the current time, you can os.rename() the
file to some temporary name, and then quickly os.rename() it back.

2) You can sort of set a file to have an arbitrary ctime, by setting the
system's clock to what you need, and then doing the rename thing above -
then restore the clock back to what it should be.

3) You can also use some sort of tool that knows the details of how inodes
are stored on disk.  You'll likely need to do this with the filesystem
unmounted at the time, though if the inode isn't currently cached in RAM,
you might be able to get away without the umount and mount.

#2 and #3 require root access typically.

If a teacher is looking for assignments on a timesharing system to have been
turned in by a certain time, the ctime is the best time field to check.

On Sun, Mar 20, 2011 at 4:52 PM, monkeys paw <monkey at joemoney.net> wrote:

> I used os.uname to succesfully change the access and mod times of
> a file. My question is, is there any other date store for a file that
> indicates the creation time, or is it impossible to detect that a file
> with an older mod/access time is actually a 'new' file?
>
> os.utime('sum.py', (time.time(),time.time())
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110320/7edf4e71/attachment-0001.html>


More information about the Python-list mailing list