Meisenzahl, Christopher1 wrote:
About 5 years ago I worked my way to the O'Reilly Perl for Win32 book,
but haven't used it since. I have a need to write a Perl app that will
check the timestamps of several known files in known locations. If the
date/time of any of the files is not the current date, send email to a
known list of recipients.

Can anyone get me started on how to check the date/time stamp of a file
and compare it to the current day? I imagine this type of simple task is
a no-brainer for almost everyone on this list. Poking back through my
book a bit now. All pointers to more info much appreciated. ;-)

Thanks very much in advance!

Here's an quick hint: use the stat() function to get the modification/creation/access time of the files, then get the current time using time(). Since the timestamps returned by both functions are in UNIX epoch seconds, you can just compare them numerically:

my ($file_atime, $file_mtime, $file_ctime) = (stat $filename)[8..10];
my $current_time = time();
if ($file_mtime != $current_time)
  {
  # ... Send e-mail!
  }


But this does not make much sense, unless what you want is to know if the file was created/modified/accessed at this very *exact* second.

Perhaps what you want is to know if the file was created/modified/accessed during the current day? If so, it is a bit more complex, since you have to compare the file timestamp to the epoch range between the midnights encompassing today. You can always use the CPAN module Date::Calc which performs a lot of date/timestamp calculations for you.

        dZ.
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to