Asad wrote:
> All:
>     I need to write a script to delete 4 hours old files and
>     directories on Windows. I am planning to use Perl to accomplish
> this. I understand the "-M" would delete at least a day old files,
> but is there a way to delete 4 hours old files and directories. Thank
> you.   

The -M operator returns a floating point value, so you can compute 4 hours
as:

  $hours = (-M $somefile) * 24;
  if ($hours > 4) {
     ...file is more than 4 hours old
  }

You need to be careful using -M in a daemon because the age is base on the
script start time and not the current time. If that's a concern, you can
make -M use current time by doing this:

  $hours = do { local $^T = time; (-M $somefile) * 24 };

or you can use stat() insteamd of -M like this:

  $hours = (time - (stat $somefile)[9]) / 3600;

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to