in reply to Notification of a new file added to directory
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Notification of a new file added to directory
by Jenda (Abbot) on Jan 03, 2003 at 18:07 UTC | |
|
Re: Re: NOtification of a new file added to directory
by Anonymous Monk on Jan 03, 2003 at 15:26 UTC | |
by gjb (Vicar) on Jan 03, 2003 at 15:43 UTC | |
by Anonymous Monk on Jan 03, 2003 at 18:00 UTC | |
|
Re: Re: NOtification of a new file added to directory
by Anonymous Monk on Jan 03, 2003 at 16:20 UTC | |
by gjb (Vicar) on Jan 03, 2003 at 16:34 UTC |