On Jun 6, 2012, at 9:45 AM, William R. Wing (Bill Wing) wrote: > On Jun 6, 2012, at 9:29 AM, Alain Ketterlin wrote: > >> loial <jldunn2...@gmail.com> writes: >> >>> 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. >> -- >> http://mail.python.org/mailman/listinfo/python-list > > If you REALLY want the creation time rather than the last time the file was > touched, you will probably have to invoke the subprocess module and call ls > -U, something like the following: > > creation_time = subprocess.check_output(["ls", "-U", > string_filename_variable]) > > The -U option isn't universal, but it does exist in most of the UNIces I'm > familiar with. > > -Bill
Addendum, with apologies - I was in too much of a hurry. The -U option has to be used with -l (at least on my system). Thus, it would be ls -lU. Alternatively, you could "stat" the file in a subprocess and then parse the return data to extract the creation date. -Bill -- http://mail.python.org/mailman/listinfo/python-list