in reply to Comparing Directories and copy files

The following should check for files which only exist in dir1 and copy them to dir2 (UNTESTED):
use strict; use warnings; use File::Slurp qw(read_dir); use File::Copy; my $dir1 = 'C:\TEST1'; my $dir2 = 'C:\TEST2'; my %files1 = map { $_ => 1 } grep { -f "$dir1/$_" } read_dir($dir1); opendir my $dh, $dir2 or die "can not open $dir2: $!"; while (my $entry = readdir $dh) { next unless -f "$dir2/$entry"; copy("$dir1/$entry" => "$dir2/$entry") unless exists $files1{$entr +y}; } closedir $dh;

Replies are listed 'Best First'.
Re^2: Comparing Directories and copy files
by Fuisms (Initiate) on Jul 27, 2010 at 21:56 UTC
    I dont use File:Copy because I do not believe that ActivePerl supports that module.
      I dont use File:Copy because I do not believe that ActivePerl supports that module.
      Firstly, File::Copy is a core module, which means that it should be included in every properly installed Perl distribution. Secondly, I use ActiveState (5.8.8), and it is installed for me. What happens when you try this at your command prompt?
      perldoc File::Copy

      Use system instead, if you want to.

        Cool, it is there.. Thanks, I didnt know it was a core module. I was looking for it on the modules I could add and it wasnt there. I will definately use it instead of system. Thanks again guys!