Compare 2 times

L

loial

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?
 
A

Alain Ketterlin

loial said:
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?

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.
 
A

Alain Ketterlin

Alain Ketterlin said:
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.

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.
 
N

Nobody

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?

Most Unix filesystems don't store a "creation" time.
 
T

t_texas

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.

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.
 
G

garabik-news-2005-05

t_texas said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,146
Messages
2,570,832
Members
47,374
Latest member
EmeliaBryc

Latest Threads

Top