use File::Copy; my ($src,$dst) = @ARGV; -d or die "$_ is not a directory" for $src,$dst; ## first pass, copy anything not there... opendir SRC, $src or die "cannot opendir $src: $!"; for (readdir SRC) { next unless -f "$src/$_"; next if -e "$dst/$_"; print "copying $src/$_ to $dst/$_...\n"; copy "$src/$_", "$dst/$_" or warn "Cannot copy!"; } closedir SRC; ## now delete the ones that don't belong there opendir DST, $dst or die "Cannot opendir $dst: $!"; for (readdir DST) { next unless -f "$dst/$_"; next if -e "$src/$_"; print "deleting $dst/$_...\n"; unlink "$dst/$_" or warn "Cannot unlink: $!"; } closedir DST;
-- Randal L. Schwartz, Perl hacker
In reply to Re: New Perl programmer looking for answer in Directory Comparisons
by merlyn
in thread New Perl programmer looking for answer in Directory Comparisons
by ATaylor
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |