in reply to Monitor directory for new files and copy only new files to another directory
this will check for if files exists and if it doesnt exists in destination, then copy. then it will also update files int he root copy to directory if they have changes, but not directories and sub directorie)use strict; use warnings; use diagnostics; use File::Copy::Recursive qw(dircopy rcopy); use File::Path qw(make_path); my $dirname = "$ENV{USERPROFILE}\\Dropped Box\\"; my $dirname2 = "C:\\Dropped Stuff\\"; 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) ) { if ( not -e $dirname2 . $filename ) { print "copying $dirname$filename to $dirname2$filename\n"; dircopy( $dirname . $filename, $dirname2 . $filename ); rcopy( $dirname . $filename, $dirname2 . $filename ); } else { print "files already exists so im skipping\n"; } } closedir(DIR); sleep $sleep; 1; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Monitor directory for new files and copy only new files to another directory
by james28909 (Deacon) on Oct 10, 2014 at 23:47 UTC |