#!/usr/bin/env perl
|
|
|
|
=pod
|
|
|
|
=head1 NAME
|
|
|
|
photocp - copy files from digital camera media to my home dir
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
# try a couple of defaults
|
|
photocp
|
|
|
|
# look in source_directory
|
|
photocp [source_directory]
|
|
|
|
=head1 AUTHOR
|
|
|
|
Brennen Bearnes
|
|
|
|
=cut
|
|
|
|
use strict;
|
|
use warnings;
|
|
|
|
use 5.10.0;
|
|
use POSIX qw(strftime);
|
|
use File::Basename;
|
|
use File::Copy;
|
|
use File::Find;
|
|
use File::HomeDir;
|
|
|
|
my $home = File::HomeDir->my_home;
|
|
my $archive_dir = $home . '/workspace/photos';
|
|
|
|
my @sources = (
|
|
'/media/' . $ENV{'USER'} . '/EOS_DIGITAL',
|
|
'/media/' . $ENV{'USER'} . '/CANON_DC',
|
|
'/media/' . $ENV{'USER'} . '/NIKON D600',
|
|
'/media/' . $ENV{'USER'} . '/NO NAME',
|
|
'/media/' . $ENV{'USER'} . '/9016-4EF8',
|
|
'/media/CANON_DC',
|
|
'/media/EOS_DIGITAL',
|
|
'/media/disk/DCIM',
|
|
'/media/NIKON D600',
|
|
'/run/user/1000/gvfs/' # XXX: this is lame.
|
|
);
|
|
|
|
my @t = localtime;
|
|
my $daydir = strftime("%Y-%m-%d", @t);
|
|
|
|
my $src;
|
|
if ((defined $ARGV[0]) && (-d $ARGV[0])) {
|
|
$src = $ARGV[0];
|
|
} else {
|
|
foreach my $source (@sources) {
|
|
if (-d $source) {
|
|
$src = $source;
|
|
last;
|
|
}
|
|
}
|
|
unless ($src) {
|
|
die 'source not mounted? tried ' . join(' ', @sources);
|
|
}
|
|
}
|
|
|
|
my $dest = $archive_dir . '/' . $daydir;
|
|
|
|
if ((-e $dest) && (! -d $dest)) {
|
|
die 'target exists but is not a directory';
|
|
}
|
|
|
|
if (! -d $dest) {
|
|
say "creating $dest";
|
|
mkdir($dest);
|
|
} else {
|
|
say "$dest exists";
|
|
}
|
|
|
|
my $count = 0;
|
|
|
|
find(
|
|
sub {
|
|
if ( /[.] (jpe?g | mpe?g | avi | raw | cr2 | tiff? | bmp | gif | mov) $/ix ) {
|
|
$count++;
|
|
my $copy_to = "$dest/$_";
|
|
if (-e $copy_to) {
|
|
say "$copy_to already exists - skipping copy";
|
|
} else {
|
|
say "copying $File::Find::name to $copy_to";
|
|
copy($File::Find::name, $copy_to)
|
|
or die "copy failed: $!";
|
|
}
|
|
}
|
|
},
|
|
$src
|
|
);
|
|
|
|
say "$count files copied";
|