Hi Monks ! I am a beginner looking for some help.
I have 2 directories, Source and Target and I would like to take every directory/file in Source dir that is not in Target dir and copy it over to Target dir. This should include sub dirs as well.
If dir/file from Source is already in Target, I would like to print its dir/file name.
So far I came up with the follwoing code, but it doesnt seem to be working.
Usage: perl mergeTrees.pl SourceDir TargetDir
use strict; use File::Find; use File::Copy; use Cwd; my $Src = $ARGV[0]; my $Trg = $ARGV[1]; my $path = getcwd(); find (\&wanted, $Src); sub wanted { opendir (DIR, "$path/$Trg") or die "cannot opendir $Trg"; foreach my $file (readdir(DIR)) { if ($_ == $file) { print "File already in $Trg: $file\n"; } else { copy("$_","$path/$Trg/$_"); } } closedir (DIR); }

In reply to How can I compare two directories and copy over files missing from one to another? by habhab

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