photo-helpers

Unnamed repository; edit this file 'description' to name the repository.
git clone git://code.clttr.info/photo-helpers.git
Log | Files | Refs | README | LICENSE

commit a1160d2e3c624e72b56e2aa711722d2177a33240
parent 250fdb50171fd0aa52c8f7020e153e79d159bd75
Author: René Wagner <rwagner@rw-net.de>
Date:   Sat,  2 May 2020 16:16:00 +0200

~rwa/photo-workflow#3: allow override of converted file extension
~rwa/photo-workflow#5: do not "fail" if a optional file (*.arp) is missing

Diffstat:
Mart_file_mover.pl | 35++++++++++++++++++++---------------
1 file changed, 20 insertions(+), 15 deletions(-)

diff --git a/art_file_mover.pl b/art_file_mover.pl @@ -16,15 +16,16 @@ use Getopt::Std; $Getopt::Std::STANDARD_HELP_VERSION = 'true'; -my $VERSION = '0.3'; +my $VERSION = '0.4'; my $PROGRAM = 'Art File Mover'; # read commandline switches our $opt_m = 0; our $opt_r = 'DNG'; our $opt_f = 'JPEG'; +our $opt_c = 'jpe{0,1}g'; -getopts('mr:f:') or die "Invalid parameters provided! See 'art_file_mover.pl --help' for more details."; +getopts('mr:f:c:') or die "Invalid parameters provided! See 'art_file_mover.pl --help' for more details."; # read remaining commandline args für destination dir # last dir will win @@ -48,38 +49,41 @@ sub move_files say "destination dir : $destination_dir"; say 'action : '. ($opt_m ? 'move' : 'list only'); say ''; - my $jpeg_destination_dir = catfile($destination_dir, $opt_f); + my $converted_destination_dir = catfile($destination_dir, $opt_f); - if ( $opt_m && (! -d $destination_dir || ! -d $jpeg_destination_dir)) + if ( $opt_m && (! -d $destination_dir || ! -d $converted_destination_dir)) { if (! -d $destination_dir ) { mkdir $destination_dir or die "Could not create destination dir $_ : $!"; } - if (! -d $jpeg_destination_dir ) { mkdir $jpeg_destination_dir or die "Could not create destination dir $_ : $!"; } + if (! -d $converted_destination_dir ) { mkdir $converted_destination_dir or die "Could not create destination dir $_ : $!"; } } # find all jpegs in current dir - my @files = File::Find::Rule->file()->name( qr/\.jpe{0,1}g$/i )->maxdepth(1)->in( catfile(getcwd, $opt_f) ); + my @files = File::Find::Rule->file()->name( qr/\.$opt_c$/i )->maxdepth(1)->in( catfile(getcwd, $opt_f) ); - foreach my $jpeg_file ( @files ) + foreach my $converted_file ( @files ) { - my ( $filename, $path, $ext ) = fileparse($jpeg_file, qr/\.[^.]*/); - my $outarp_file = $jpeg_file. '.out.arp'; + 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 $rawarp_file = $raw_file. '.arp'; print $raw_file .'...'; $move_counter++; - # do not move file s that have no raw-file anymore + # do not move files that have no raw-file anymore if ( ! -e $raw_file ) { print 'raw-file not found!'; } elsif ( $opt_m ) { - if ( move($jpeg_file, catfile($jpeg_destination_dir, basename($jpeg_file))) && - move($outarp_file, catfile($jpeg_destination_dir, basename($outarp_file))) && - move($raw_file, catfile($destination_dir, basename($raw_file))) && - move($rawarp_file, catfile($destination_dir, basename($rawarp_file))) + # only warn if JPEG or RAW file could not be moved + # 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 ( move($converted_file, catfile($converted_destination_dir, basename($converted_file))) && + move($raw_file, catfile($destination_dir, basename($raw_file))) ) { print 'moved.'; @@ -111,7 +115,8 @@ sub main::HELP_MESSAGE say 'commandline parameters - should be combined to match your needs:'; say 'art_file_mover.pl <folder> - list all found files in the current working directory that will eventually be moved'; say 'art_file_mover.pl -m <folder> - move all converted files and their raws to the given folder'; - say 'art_file_mover.pl -r <rawextension> - override the raw extensions , defaults to "DNG"'; + say 'art_file_mover.pl -r <rawextension> - override the raw extensions, defaults to "DNG"'; say 'art_file_mover.pl -f <folder> - override the folder for converted JPEGs, defaults to "JPEG"'; + say 'art_file_mover.pl -c <extension> - override the converted file extenion (case-insensitive), defaults to "jp(e)g"'; say 'art_file_mover.pl --help - show this help'; }