in reply to Find the Files added to the directory in Linux.

There is more than one way to skin this cat. Here is one way using the Linux inotify facility

See Linux::Inotify for details

use strict; use warnings; use Linux::Inotify; my $notifier = Linux::Inotify->new(); my $watch = $notifier->add_watch('/directory/to/monitor', Linux::Inoti +fy::CREATE); while (1) { for my $event ($notifier->read()) { print "New file named: " . $event->fullname() . "\n"; } }

Replies are listed 'Best First'.
Re^2: Find the Files added to the directory in Linux.
by flexvault (Monsignor) on Jul 05, 2013 at 11:22 UTC

    Loops,

    I would recommend you include a 'sleep' or 'usleep' to your 'while' loop. Otherwise you will eat up a lot of the computer!

    Regards...Ed

    "Well done is better than well said." - Benjamin Franklin

      No, sleep and usleep would be counter productive and just slow detection down. The whole beauty of iNotify is that the process sleeps until an event happens, and then its woken by the kernel and passed the event structure. The code as is takes next to zero system resources.

        Loops,

        That little bit of wisdom should be added to the description of iNotify. I checked before commenting.

        Regards...Ed

        "Well done is better than well said." - Benjamin Franklin