commit b51a0f4a61c49facce5be307718e9fa4779ed35e
parent bb1d52906f3530accc153438021efcec31d72f24
Author: René Wagner <rwagner@rw-net.de>
Date: Thu, 15 Oct 2020 22:03:21 +0200
ref rwa/photo-workflow#56: copy images to additional dir
ref ~rwa/photo-workflow#59: switch to uppercase params
Diffstat:
M | afm.pl | | | 39 | +++++++++++++++++++++++---------------- |
1 file changed, 23 insertions(+), 16 deletions(-)
diff --git a/afm.pl b/afm.pl
@@ -14,21 +14,21 @@ use Getopt::Std;
$Getopt::Std::STANDARD_HELP_VERSION = 'true';
-my $VERSION = '0.6';
+my $VERSION = '0.7';
my $PROGRAM = 'ART File Mover';
my $configfile = catfile(File::HomeDir->my_home, '.afm.conf');
# read commandline switches
our $opt_l = 0;
-our $opt_r = 'DNG';
-our $opt_f = 'JPEG';
-our $opt_e = 'jpe{0,1}g';
-our $opt_s = 0;
+our $opt_R = 'DNG';
+our $opt_F = 'JPEG';
+our $opt_E = 'jpe{0,1}g';
+our $opt_C = '';
getconfig();
-getopts('slr:f:e:') or die "Invalid parameters provided! See 'afm.pl --help' for more details.";
+getopts('lR:F:E:C:') or die "Invalid parameters provided! See 'afm.pl --help' for more details.";
# read remaining commandline args für destination dir
# last dir will win
@@ -41,7 +41,7 @@ foreach my $arg ( @ARGV )
if ($destination_dir eq getcwd) { $opt_l = 1; }
-if ( $opt_s ) { writeconfig(); }
+writeconfig();
move_files($destination_dir);
@@ -53,12 +53,13 @@ sub move_files
my $move_counter = 0;
say "destination dir : $destination_dir";
- say "raw file ext : $opt_r";
- say "output file dir : $opt_f";
- say "output file ext : $opt_e";
+ ($opt_C eq '') or say "copy dir : $opt_C";
+ say "raw file ext : $opt_R";
+ say "output file dir : $opt_F";
+ say "output file ext : $opt_E";
say 'action : '. ($opt_l ? 'list only' : 'move');
say '';
- my $converted_destination_dir = catfile($destination_dir, $opt_f);
+ my $converted_destination_dir = catfile($destination_dir, $opt_F);
if ( !$opt_l && (! -d $destination_dir || ! -d $converted_destination_dir))
{
@@ -67,13 +68,13 @@ sub move_files
}
# find all jpegs in current dir
- my @files = File::Find::Rule->file()->name( qr/\.$opt_e$/i )->maxdepth(1)->in( catfile(getcwd, $opt_f) );
+ my @files = File::Find::Rule->file()->name( qr/\.$opt_E$/i )->maxdepth(1)->in( catfile(getcwd, $opt_F) );
foreach my $converted_file ( @files )
{
my ( $filename, $path, $ext ) = fileparse($converted_file, qr/\.[^.]*/);
my $outarp_file = $converted_file. '.out.arp';
- my $raw_file = catfile(dirname($path), $filename .'.'. $opt_r);
+ my $raw_file = catfile(dirname($path), $filename .'.'. $opt_R);
my $rawarp_file = $raw_file. '.arp';
print $raw_file .'...';
@@ -90,6 +91,11 @@ sub move_files
# the processing files *.arp are optional and are fine to be absent
move($outarp_file, catfile($converted_destination_dir, basename($outarp_file)));
move($rawarp_file, catfile($destination_dir, basename($rawarp_file)));
+
+ if ($opt_C ne '' && -d $opt_C)
+ {
+ copy($converted_file, catfile($opt_C, basename($converted_file)));
+ }
if ( move($converted_file, catfile($converted_destination_dir, basename($converted_file))) &&
move($raw_file, catfile($destination_dir, basename($raw_file)) ))
@@ -115,9 +121,10 @@ sub getconfig
sub writeconfig
{
open(my $filehandle, '>', $configfile) or die "Could not open file '$configfile': $!";
- say $filehandle '$opt_f="'. $opt_f .'";';
- say $filehandle '$opt_e="'. $opt_e .'";';
- say $filehandle '$opt_r="'. $opt_r .'";';
+ say $filehandle '$opt_F="'. $opt_F .'";';
+ say $filehandle '$opt_E="'. $opt_E .'";';
+ say $filehandle '$opt_R="'. $opt_R .'";';
+ say $filehandle '$opt_C="'. $opt_C .'";';
close $filehandle;
}