monitor files in a directory using perl
Friday, May 28, 2010 9:29:36 AM
#!/usr/bin/perl
while (true) {
opendir (DIR, "/work/perl/tmp") or die "Cannot open /my/dir: $!\n";
my @Dircontent = readdir DIR;
close DIR;
my $items_in_dir = @Dircontent;
if ($items_in_dir > 2) { # > 2 because of "." and ".."
print @Dircontent;
# do_something_now(); # takes file(s) and moves them
}
#else {sleep 100;}
}
REFERENCE: how to permanently monitor a directory
http://www.perlmonks.org/?node_id=283849
while (true) {
opendir (DIR, "/work/perl/tmp") or die "Cannot open /my/dir: $!\n";
my @Dircontent = readdir DIR;
close DIR;
my $items_in_dir = @Dircontent;
if ($items_in_dir > 2) { # > 2 because of "." and ".."
print @Dircontent;
# do_something_now(); # takes file(s) and moves them
}
#else {sleep 100;}
}
REFERENCE: how to permanently monitor a directory
http://www.perlmonks.org/?node_id=283849






