photo-helpers

collection of small Perl scripts with some useful file management functions for photographers
git clone git://git.clttr.info/photo-helpers.git
Log (Feed) | Files | Refs (Tags) | README | LICENSE

commit f6adb228fdce67632b450f391c0f510cfc948d98
parent 2adcde42410f4aebeadeb62d198f0c733583dd3b
Author: René Wagner <rwa@clttr.info>
Date:   Sun,  6 Nov 2022 17:50:07 +0100

afm: introduce -f param for file filtering

Diffstat:
Mafm | 56++++++++++++++++++++++++++++++--------------------------
1 file changed, 30 insertions(+), 26 deletions(-)

diff --git a/afm b/afm @@ -14,7 +14,7 @@ use Getopt::Std; $Getopt::Std::STANDARD_HELP_VERSION = 'true'; -my $VERSION = '0.8'; +my $VERSION = '1.0'; my $PROGRAM = 'ART File Mover'; my $configfile = catfile(File::HomeDir->my_home, '.afm.conf'); @@ -25,10 +25,11 @@ our $opt_R = 'DNG'; our $opt_F = 'JPEG'; our $opt_E = 'jpe{0,1}g'; our $opt_C = ''; +our $opt_f = ''; getconfig(); -getopts('lR:F:E:C:') or die "Invalid parameters provided! See 'afm --help' for more details."; +getopts('lR:F:E:C:f:') or die "Invalid parameters provided! See 'afm --help' for more details."; # read remaining commandline args für destination dir # last dir will win @@ -53,7 +54,8 @@ sub move_files my $move_counter = 0; say "destination dir : $destination_dir"; - ($opt_C eq '') or say "copy dir : $opt_C"; + ($opt_C eq '') or say "copy dir : $opt_C"; + say "file filter : $opt_f"; say "raw file ext : $opt_R"; say "output file dir : $opt_F"; say "output file ext : $opt_E"; @@ -68,7 +70,7 @@ 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 )->name( qr/$opt_f/ )->maxdepth(1)->in( catfile(getcwd, $opt_F) ); foreach my $converted_file ( @files ) { @@ -97,11 +99,11 @@ sub move_files move($rawarp2_file, catfile($destination_dir, basename($rawarp2_file))); move($xmp_file, catfile($destination_dir, basename($xmp_file))); move($xmp2_file, catfile($destination_dir, basename($xmp2_file))); - - if ($opt_C ne '' && -d $opt_C) - { - copy($converted_file, catfile($opt_C, basename($converted_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)) )) @@ -144,21 +146,23 @@ sub main::VERSION_MESSAGE() 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 'usage: afm [options] <target folder>'; - say ''; - say 'options:'; - say ' -l : list-only mode - does not move files but only lists which files would be moved'; - say ' -R <raw> : override the raw extensions, defaults to "DNG"'; - say ' This option is automatically saved in the user config and can be omitted on the next run'; - say ' -F <folder> : override the folder for converted files, defaults to "JPEG"'; - say ' This option is automatically saved in the user config and can be omitted on the next run'; - say ' -E <ext> : override the converted file extenion (case-insensitive), defaults to "jp(e)g"'; - say ' Perl-compatible regular expressions allowed'; - say ' This option is automatically saved in the user config and can be omitted on the next run'; - say ' -C <folder> : copy the converted (output) files (ie jpegs) to an additional directory'; - say ' This option is automatically saved in the user config and can be omitted on the next run'; - say ' --help : show this help'; + say ''; + say 'Find all by ART converted files in the current folder and their corresponding RAWs and move them to specified directory.'; + say ''; + say 'usage: afm [options] <target folder>'; + say ''; + say 'options:'; + say ' -l : list-only mode - does not move files but only lists which files would be moved'; + say ' -f <exp> : filter files by regex - only raw files that match the PCRE are processed'; + say ' needs to be quoted'; + say ' -R <raw> : override the raw extensions, defaults to "DNG"'; + say ' This option is automatically saved in the user config and can be omitted on the next run'; + say ' -F <folder> : override the folder for converted files, defaults to "JPEG"'; + say ' This option is automatically saved in the user config and can be omitted on the next run'; + say ' -E <ext> : override the converted file extenion (case-insensitive), defaults to "jp(e)g"'; + say ' Perl-compatible regular expressions allowed'; + say ' This option is automatically saved in the user config and can be omitted on the next run'; + say ' -C <folder> : copy the converted (output) files (ie jpegs) to an additional directory'; + say ' This option is automatically saved in the user config and can be omitted on the next run'; + say ' --help : show this help'; }