Why not use the -M operator to test for the age of the file (result in days). So something like:
would do.sub test_new { my ($mydir) = @_; my $new_one = 0; opendir(DIR, $mydir) or die("..."); while (my $file = readdir(DIR)) { if ($file !~ /^\.+$/ && -M $mydir . '/' . $file < 0.5) { $new_one = 1; last; } } closedir(DIR); return $new_one; }
Hope this helps, -gjb-
Update: Stupid me! I tested the script only in the current working directory, obviously the file test should read -M $mydir . '/' . $file < 0.5 rather than -M $file < 0.5 which looks for the file in the script's directory. (modified the original code already). Incidently, the error is easily caught with use warnings; since a warning about the use of an uninitialized value in numeric lt is issued.
Update: Added code to filter out the . and .. directories that were tested as well.
In reply to Re: Notification of a new file added to directory
by gjb
in thread Notification of a new file added to directory
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |