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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.