Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Compare 2 times

69 views
Skip to first unread message

loial

unread,
Jun 6, 2012, 8:50:02 AM6/6/12
to
I have a requirement to test the creation time of a file with the
current time and raise a message if the file is more than 15 minutes
old.

Platform is Unix.

I have looked at using os.path.getctime for the file creation time and
time.time() for the current time, but is this the best approach?



Alain Ketterlin

unread,
Jun 6, 2012, 9:29:37 AM6/6/12
to
No. getctime() returns the last "change" time. The creation time is not
kept anywhere. This may still match your requirement though. And os.path
is the right package to look at for such tasks.

-- Alain.

Alain Ketterlin

unread,
Jun 6, 2012, 10:03:52 AM6/6/12
to
Sorry, it may happen that the filesystem you're working with provides
that time, in which case it's called birthtime. This _may_ be available
via os.stat().

-- Alain.

Nobody

unread,
Jun 6, 2012, 2:20:55 PM6/6/12
to
Most Unix filesystems don't store a "creation" time.

t_texas

unread,
Jun 6, 2012, 11:49:38 PM6/6/12
to
Unless you are using ext4 you are going to have to store the creation
time yourself. If the files are coming from your application, use the
sqlite3 or shelve module to store the creation time for each file then
check that data to determine which files are more than 15 minutes old.

If the files are being generated from another application or from
users, have your application check the directory every minute and
record any new files. Worst case scenario, a file will be present for
16 minutes vs 15.

garabik-ne...@kassiopeia.juls.savba.sk

unread,
Jun 10, 2012, 2:31:02 AM6/10/12
to
t_texas <tye...@gmail.com> wrote:
> On Jun 6, 7:50 am, loial <jldunn2...@gmail.com> wrote:
>> I have a requirement to test the creation time of a file with the
>> current time and raise a message if the file is  more than 15 minutes
>> old.
>>
>> Platform is Unix.
>>
>> I have looked at using os.path.getctime for the file creation time and
>> time.time() for the current time, but is this the best approach?
>
> Unless you are using ext4 you are going to have to store the creation
> time yourself. If the files are coming from your application, use the
> sqlite3 or shelve module to store the creation time for each file then
> check that data to determine which files are more than 15 minutes old.
>

pyinotify might be worth a look

--
-----------------------------------------------------------
| Radovan Garabík http://kassiopeia.juls.savba.sk/~garabik/ |
| __..--^^^--..__ garabik @ kassiopeia.juls.savba.sk |
-----------------------------------------------------------
Antivirus alert: file .signature infected by signature virus.
Hi! I'm a signature virus! Copy me into your signature file to help me spread!
0 new messages