471,073 Members | 1,366 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,073 software developers and data experts.

Re: Checking a file's time stamp -- followup

Christian Heimes wrote:
>William Purcell wrote:
>>Hi all,
I am wanting to check to see the last time a file was edited. For
example, I
have a directory containing two text files, file1.txt and
file2.txt. I
want to be able to process these files but only if they have been
since the last time they were processed. I think that I want to be
able to
check the time stamp of each file. Can anyone tell me how to do that or
point me in a better direction of checking the last time a file was

> >>import os
stat = os.stat("/etc/passwd")
print stat
(33188, 362259, 2053L, 1, 0, 0, 1690, 1218550501, 1218118498,
> >>dir(stat)
['__add__', '__class__', '__contains__', '__delattr__', '__doc__',
'__eq__', '__ge__', '__getattribute__', '__getitem__',
'__getslice__', '__gt__', '__hash__', '__init__', '__le__',
'__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__',
'__reduce_ex__', '__repr__', '__rmul__', '__setattr__', '__str__',
'n_fields', 'n_sequence_fields', 'n_unnamed_fields', 'st_atime',
'st_blksize', 'st_blocks', 'st_ctime', 'st_dev', 'st_gid', 'st_ino',
'st_mode', 'st_mtime', 'st_nlink', 'st_rdev', 'st_size', 'st_uid']
> >>stat.st_mtime

use these shortcuts, IMHO they are easier than os.stat.

os.path.getmtime() - get modified time
os.path.atime() - get last accessed time (careful some admins turn
off on their servers for performance reasons)
os.path.ctime() - get creation time
Is it possible to change the time stamp of a file (Win2K platform)? If
yes, how?
Aug 13 '08 #1
0 1090

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by The Biscuit Eater | last post: by
1 post views Thread by Abhijit Bhadra | last post: by
2 posts views Thread by Christopher | last post: by
6 posts views Thread by Mike Charney | last post: by
reply views Thread by Edwin.Madari | last post: by
reply views Thread by Rob Weir | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.