While this will work fine if the files are CREATED there, it may fail badly it they are MOVED. At least if they are moved within one logical disk.
I'd use a hash tied to a DBM containing the last modification dates of all files in the directory and processed all that 1) were not present or 2) have a different modification time.
use DB_File; tie %ages, 'DB_File', $age_database, O_CREAT|O_RDWR, 0700; sub test_new { my ($mydir) = @_; my $new_one = 0; opendir(DIR, $mydir) or die("..."); while (my $file = readdir(DIR)) { next if $file !~ /^\.+$/; my $mtime = (stat($file))[9]; next if $mtime == $ages{$file}; $ages{$file} = $mtime; #the $file is new! Process it any way you like $new_one = 1; } closedir(DIR); return $new_one; }
If all you need to know is whether there was any change then maybe it would be better to generate an MD5 hash of the directory contents (filenames + their modification times) and compare the result with a stored value.
Jenda
In reply to Re: Re: Notification of a new file added to directory
by Jenda
in thread Notification of a new file added to directory
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |