Skip to content

Instantly share code, notes, and snippets.

@leedo
Created December 3, 2011 00:34
Show Gist options
  • Save leedo/1425520 to your computer and use it in GitHub Desktop.
Save leedo/1425520 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use File::Next;
use File::Copy;
use File::Path qw/mkpath/;
my ($source, $dest) = @ARGV;
die "need source and dest" unless -e $source and -e $dest;
my $iter = File::Next::files({ file_filter => sub {/\.(?:png|jpe?g|gif)/i} }, $source);
my $offset = length $source;
while (my $file = $iter->()) {
$file = substr($file, $offset);
my ($path, $file) = $file =~ m{(.+/)([^/]+)$};
next if -e '$dest/$path/$file';
if (! -e "$dest/$path") {
mkpath("$dest/$path", 1, 0755);
}
print "copying $file from $source/$path to $dest/$path\n";
copy("$source/$path/$file", "$dest/$path/$file");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment