I am writing some code which scans through a directory looking at all files within and checking for the modification date of each file. I want to know the age of each file so i am comparing the epoch mod time to the present epoch time. This shouldwork fine but i am getting mod file times which are older than todays epoch time (???)
the following code was executed at Mar 5 12:18:27 2002
To find the epoch time for now i used the code:
#split date into seperate vars
my($day, $month, $mday, $time, $year) = split(" ", $datetime);
my($timeh, $timem, $times) = split(':', $time);
#this function calculates the number of seconds that have passed since
+ Midnight, January 1, 1970
my $time = timegm($times,$timem,$timeh,$mday,$month,$year);
$time gave the present epoch time of
1010233107
to find the mod epoch time of files i used the code
find (\&checkfile, "/home/costas");
sub checkfile {
my @stats = stat $_;
$fileage = $time-$stats[9];
my @filetime = localtime($stats[9]);
my $year = $filetime[5]+1900;
print "$File::Find::name Epoch mod : $stats[9], LT mo
+d $filetime[2]:$filetime[1]:$filetime[0] $filetime[4]/$year, Age o
+f
+ file : $fileage <br>";
}
Note that oin the above code i have printed the localtime mod time as well as the epoch mod time.
THe result i get for a particular file is:
/home/costas/index.html Epoch mod :
1015330245, LT mod
12:10:45 2/2002, Age of file :
-5097138
In order to find the a of age of this file in epoch time i simply subtracted the epoch mod time from the current mod time. The problem as you can see is that the age of time is NEGATIVE which would mean that the file is OLDER than the current time despite the fact that the localtime of this file shows this to be untrue.
Can anybody see why this is so.
Thanks in advance
Costas
PS i posted this about two hours ago but for some reason I cannot ssee the responses that have been posted!!! Also my questions do not appear on the monastery gates.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.