art-helpers

simple helper scripts for managing images processed by ART
git clone https://git.clttr.info/art-helpers.git
Log (Feed) | Files | Refs (Tags) | README | LICENSE

commit 16b4dfaaf952767e94a58bf35da168bc56c37282
parent 241bc3e756e131cd09a664867fc128eb84abd098
Author: René Wagner <rwagner@rw-net.de>
Date:   Thu, 12 Mar 2020 09:12:44 +0100

art_file_mover.pl v0.1 - implement basic features

Diffstat:
Aart_file_mover.pl | 116+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 116 insertions(+), 0 deletions(-)

diff --git a/art_file_mover.pl b/art_file_mover.pl @@ -0,0 +1,116 @@ +#!/usr/bin/perl +# Copyright(c) René Wagner 2019-2020 +# published under BSD 3-Clause License +# https://git.clttr.info/photo-helpers/ + +use warnings; +use strict; +use feature qw(say); +use Cwd; +use File::Basename; +use File::Copy; +use File::Find; +use File::Find::Rule; +use File::Spec::Functions; +use Getopt::Std; + +$Getopt::Std::STANDARD_HELP_VERSION = 'true'; + +my $VERSION = '0.1'; +my $PROGRAM = 'Art File Mover'; + +# read commandline switches +our $opt_m = 0; +our $opt_r = 'DNG'; +our $opt_f = 'JPEG'; + +if ( !getopts('mr:f:') ) +{ + die("Invalid parameters provided! See 'art_file_mover.pl --help' for more details."); +} + +# read remaining commandline args +# last dir will win +# TODO: handle if destination dir is current dir or empty +my $destination_dir = getcwd; +foreach my $arg ( @ARGV ) +{ + $destination_dir = $arg; +} + +move_files($destination_dir); + +exit 0; + +sub move_files +{ + my ( $destination_dir ) = @_; + my $move_counter = 0; + + say "destination dir : $destination_dir"; + say 'action : '. ($opt_m ? 'move' : 'list only'); + say ''; + + if ( $opt_m && (! -d $destination_dir || ! -d catfile($destination_dir, $opt_f))) + { + mkdir $destination_dir or die "Could not create destination dir $_ : $!"; + mkdir catfile($destination_dir, $opt_f) 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) ); + + foreach my $jpeg_file ( @files ) + { + my ( $filename, $path, $ext ) = fileparse($jpeg_file, qr/\.[^.]*/); + my $outarp_file = $jpeg_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 + if ( ! -e $raw_file ) + { + print 'raw-file not found!'; + } + elsif ( $opt_m ) + { + if ( move($jpeg_file, catfile($destination_dir, $opt_f, basename($jpeg_file))) && + move($outarp_file, catfile($destination_dir, $opt_f, basename($outarp_file))) && + move($raw_file, catfile($destination_dir, basename($raw_file))) && + move($rawarp_file, catfile($destination_dir, basename($rawarp_file))) + ) + { + print 'moved.'; + } + else + { + print "move failed: $!"; + } + } + say ''; + } + + say "\r\nfound $move_counter files."; +} + +sub main::VERSION_MESSAGE() +{ + say $PROGRAM . ' - version ' . $VERSION; + say 'published under BSD 3 - Clause License'; + say 'Copyright(c) 2019-2020 René Wagner'; + say 'https://git.clttr.info/photo-helpers/'; +} + +sub main::HELP_MESSAGE +{ + say ''; + say 'Find all by ART converted files in the current folder and their corresponding RAWs and move them to specified directory'; + say ''; + say 'commandline parameters:'; + say 'art_file_mover.pl <folder> - list all found files in the given directory that will eventually be moved'; + say 'art_file_mover.pl -m <folder> - move all converted files and their raws'; + say 'art_file_mover.pl --help - show this help'; +}