473,382 Members | 1,752 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,382 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 2903
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
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.