473,387 Members | 1,501 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Re: Checking a file's time stamp.

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 edited
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 edited?
>>import os
stat = os.stat("/etc/passwd")
print stat
(33188, 362259, 2053L, 1, 0, 0, 1690, 1218550501, 1218118498, 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
1218118498.0

Aug 12 '08 #1
1 2904
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 edited
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
edited?

>>import os
>>stat = os.stat("/etc/passwd")
>>print stat
(33188, 362259, 2053L, 1, 0, 0, 1690, 1218550501, 1218118498, 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
1218118498.0
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 this
off on their servers for performance reasons)
os.path.ctime() - get creation time
-Larry
Aug 12 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: The Biscuit Eater | last post by:
Greetings from a second day newbie to php. I think I have figured out a way to explode a field in a csv file (like 11-08-03) and implode it as 031108 and then compare it to the current date(ymd)...
0
by: Edwin.Madari | last post by:
os.paht.gmtime(path) returns the last modification of path. check out http://docs.python.org/lib/module-os.path.html regards Edwin -----Original Message----- From:...
0
by: Virgil Stokes | last post by:
Christian Heimes wrote: Is it possible to change the time stamp of a file (Win2K platform)? If yes, how?
0
by: Rob Weir | last post by:
On 13 Aug 2008, Virgil Stokes wrote: os.utime, http://docs.python.org/lib/os-file-dir.html. -- -rob
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.