I am trying to monitor a capture directory for new files. Then copy only these new files to another directory 2. I currently have this bit of code which works fantastic other than I need it to ignore files that have already been copied from directory 1. Files on directory 2 will be immediately processed and deleted.
#!/usr/bin/perl -w use strict; use File::Copy; use File::stat; use POSIX qw(strftime); my $dirname = "R:"; my $dirname2 = "M:"; my $filterstring = "\\.mpg\$"; my $sleep = 5; # how long to sleep for while (1) { opendir ( DIR, $dirname ) || die "Error in opening dir $dirname\n" +; foreach my $filename (readdir(DIR)) { next if not $filename =~ m/$filterstring/; my $old_file = $dirname . $filename; my $new_file = $dirname2 . $filename; print "Copying $old_file to $new_file\n"; copy($old_file, $new_file); } closedir(DIR); sleep $sleep; 1; }
In reply to Monitor directory for new files and copy only new files to another directory by JasonVoorheez
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |