top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Fetching File Creation Date in perl

+1 vote
348 views

I am working on a script to rename files after a formula (discussed here: http://www.drbunsen.org/naming-and-searching-files-part-1/ ) . The formula calls for an ID string that is constructed from the date and time the file is created, of the format YYYMMDD_HHMMSS. The closest approximation of the file creation date that I can find thus far is the inode change time returned by the stat() function. I was under the impression that this would not be too far off from the first save date, but from what I later read and my experimentation, it seems VERY far off the vast majority of the time. The inode change time is more often than not exactly the same as the last modification time, and even when it's not it's nowhere close to the actual date/time of the first time the file was saved.

The ID string here serves two purposes: to make a unique identifier, and to put the files in order by creation date and time. At the very least I figure using the inode change time should produce unique identifiers, but I would like to have chronological order if possible. Unfortunately, I am starting to believe that this is not possible. I have files going back to the mid 1990's, coming from various versions of Windows, as well as files produced over the last few years natively on the Mac. Even the creation dates/times of the native Mac files, as listed in the finder, seem radically incorrect.

Does anyone know if this is possible? Or should I just accept the fact that all dates before 8/2013 are suspect?

posted Aug 16, 2013 by Satish Mishra

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

There is no datum that is closely correlated to the "file creation" time.

answer Aug 16, 2013 by anonymous
Similar Questions
+3 votes

How to print current date and time in C/C++, sample program will help?

+3 votes

I am trying to calculate a date sequence using $i in conjunction with " (so the represented # is "seen" by PHP)

The code results in 2 errors:

Notice: Undefined variable: i_days_ago in test.php on line 9
Notice: Undefined variable: i_days_ago in test.php on line 13

Is there a way to do this without creating these errors and also "NOTICE" errors? The dates being calculated will be used in a database query (used to generate a report based on the activity between the starting and ending dates).

+2 votes

I always hate dealing with date/time stuff in php - never get it even close until an hour or two goes by....

anyway I have this:

// get two timestamp values
$exp_time = $_COOKIE[$applid."expire"];
$curr_time = time();
// get the difference
$diff = $exp_time - $curr_time;
// produce a display time of the diff
$time_left = date("h:i:s",$diff);

Currently the results are:

exp_time is 06:55:07
curr_time is 06:12:03
the diff is 2584
All of these are correct.

BUT time_left is 07:43:04 when it should be only "00:43:04". So - where is the hour value of '07' coming from?? And how do I get this right?

...