Last active
December 28, 2015 09:29
-
-
Save davetang/7479769 to your computer and use it in GitHub Desktop.
Perl script that takes two directory paths, one old and one new, compares the two and copies directories in the old to the new if it doesn't exist.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env perl | |
use strict; | |
use warnings; | |
my $usage = "Usage: $0 <old_dir> <new_dir>\n"; | |
my $old = shift or die $usage; | |
my $new = shift or die $usage; | |
my %current = (); | |
opendir(NEW,$new) || die "Could not open directory $new: $!\n"; | |
while(my $infile = readdir(NEW)){ | |
next if $infile =~ /^\./; | |
next unless -d "$new/$infile"; | |
$current{$infile} = 1; | |
} | |
closedir(NEW); | |
opendir(OLD,$old) || die "Could not open directory $old: $!\n"; | |
while(my $infile = readdir(OLD)){ | |
next if $infile =~ /^\./; | |
next unless -d "$old/$infile"; | |
next if exists $current{$infile}; | |
my $command = "cp -r $old/$infile $new"; | |
warn("Running $command\n"); | |
system($command); | |
} | |
closedir(OLD); | |
exit(0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment