Find file
Fetching contributors…
Cannot retrieve contributors at this time
57 lines (40 sloc) 1.29 KB
#!/usr/bin/env perl
use strict;
use warnings;
use feature ':5.10';
my $directory = $ARGV[0] // '.';
opendir my $dir, $directory or die "Can't open dir `$directory': $!";
my @file = sort grep { not /^\.{1,2}$/ } readdir $dir;
closedir $dir;
if (-d 'out') {
say "`out' directory already exists!";
sleep 3;
} else {
mkdir 'out' or die "Can't create 'out': $!";
}
my @jpeg = grep { -f and /\.jpg$/i} @file;
# Go through all the JPEG files and find the equivalent CR2 and UFRAW
# files, rar them up and append them to the JPEG
for my $jpeg (@jpeg) {
my ($name, $ext) = split /\./, $jpeg;
my @append = grep { /^$name\.(?i:cr2|ufraw)$/ } @file;
if (!@append) {
say "No cr2 or ufraw files for $jpeg, skipping";
next;
}
if (-f "out/$jpeg") {
say "out/$jpeg already exists";
next;
}
$, = ",";
say "$jpeg -> append @append";
my $cmd;
$cmd = "rar a $name.rar @append";
system $cmd and die "Command `$cmd' failed with code `$?'";
$cmd = "cat $jpeg $name.rar >> $jpeg.new";
system $cmd and die "Command `$cmd' failed with code `$?'";
$cmd = "rm $name.rar";
system $cmd and die "Command `$cmd' failed with code `$?'";
$cmd = "mv $jpeg.new out/$jpeg";
system $cmd and die "Command `$cmd' failed with code `$?'";
}