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 520120122224f968b9c4429aa6b05103262a6a91
parent fd0004000f74ca90a2207d95fe42e61951f4db1a
Author: René Wagner <apollo@rw-net.de>
Date:   Mon, 30 Sep 2019 19:20:57 +0200

#0000033 file search case-insensitive
use "say" instead of "print" for better code readability

Diffstat:
Mjpegdivider.pl | 41++++++++++++++++++++++++-----------------
Mmultiversion_sidecar_cleaner.pl | 62++++++++++++++++++++++++++++++++++----------------------------
Morphaned_sidecar_cleaner.pl | 53++++++++++++++++++++++++++++++-----------------------
3 files changed, 88 insertions(+), 68 deletions(-)

diff --git a/jpegdivider.pl b/jpegdivider.pl @@ -5,6 +5,7 @@ use warnings; use strict; +use feature qw(say); use Cwd; use File::Basename; use File::Find; @@ -38,8 +39,8 @@ sub main my ( $dir ) = @_; my ( $move_counter ) = 0; - print "working directory: $dir \r\n"; - print "moving jpeg files to subfolder:\r\n"; + say "working directory: $dir"; + say "moving jpeg files to subfolder: $SUBFOLDER \r\n"; my $destination_dir = "$dir\/$SUBFOLDER"; @@ -48,30 +49,36 @@ sub main mkdir $destination_dir or die "Could not create destination dir $_ : $!"; } - my @files = File::Find::Rule->file()->name( '*.jpg', '*.jpeg', '*.JPG', '*.JPEG' )->maxdepth(1)->in( $dir ); + my @files = File::Find::Rule->file()->name( qr/\.jpe{0,1}g$/i )->maxdepth(1)->in( $dir ); foreach my $file ( @files ) { print $file .'...'; $move_counter++; - move($file, "$destination_dir\/".basename($file) ) or warn " move failed: $!"; - print "\r\n"; + if ( move($file, $destination_dir. '/' .basename($file) ) ) + { + say "moved."; + } + else + { + say "move failed: $!"; + } } - print "\r\nmoved $move_counter jpeg files to subfolder.\r\n"; + say "\r\nmoved $move_counter jpeg files to subfolder."; } sub show_help { - print $PROGRAM . ' - version ' . $VERSION . "\r\n"; - print "published under BSD 3 - Clause License \r\n"; - print "Copyright(c) 2019 René Wagner\r\n"; - print "https://www.codewolke.net/silkypix-helper/ \r\n"; - print "\r\n"; - print "Moves JPEG files to a designated subfolder, by default 'JPEG'\r\n"; - print "\r\n"; - print "commandline parameters:\r\n"; - print "jpegdivider.pl - create a subfolder 'JPEG' in the current working dir and move jpeg files in there\r\n"; - print "jpegdivider.pl <folder> - create a subfolder 'JPEG' in the given directory and move jpeg files in there\r\n"; - print "jpegdivider.pl -h - show this help\r\n"; + say $PROGRAM . ' - version ' . $VERSION; + say 'published under BSD 3 - Clause License'; + say 'Copyright(c) 2019 René Wagner'; + say 'https://www.codewolke.net/silkypix-helper/'; + say ''; + say 'Moves JPEG files to a designated subfolder, by default "JPEG"'; + say ''; + say 'commandline parameters:'; + say 'jpegdivider.pl - create a subfolder "JPEG" in the current working dir and move jpeg files in there'; + say 'jpegdivider.pl <folder> - create a subfolder "JPEG" in the given directory and move jpeg files in there'; + say 'jpegdivider.pl -h - show this help'; } diff --git a/multiversion_sidecar_cleaner.pl b/multiversion_sidecar_cleaner.pl @@ -5,13 +5,14 @@ use warnings; use strict; +use feature qw(say); use Cwd; use File::Basename; use File::Find::Rule; use File::Find; use Switch; -my $VERSION = '0.1'; +my $VERSION = '0.2'; my $PROGRAM = 'Multiversion Sidecar Cleaner'; my $delete_flag = 0; @@ -36,29 +37,35 @@ sub main my ( $dir, $delete ) = @_; my ( $delcounter ) = 0; - print "working directory: $delete_dir \r\n"; - print 'action : '. ($delete_flag ? 'delete' : 'list only') . "\r\n \r\n"; - print "files with newer versions:\r\n"; + say "working directory: $delete_dir"; + say 'action : '. ($delete_flag ? 'delete' : 'list only') . "\r\n"; + say 'files with newer versions:'; # alle Dateien in allen Unterordnern *.spd *.spf suchen - my @files = File::Find::Rule->file->name( '*.spd', '*.spf' )->in( $dir ); + my @files = File::Find::Rule->file->name( qr/\.sp(d|f)$/i )->in( $dir ); foreach my $file ( @files ) { if ( exist_newer_file($file) ) { - print $file .'...newer file found!'; + print $file .'...'; $delcounter++; if ( $delete ) { - unlink $file or warn " Deletion failed: $!"; - } - print "\r\n"; + if ( unlink $file ) + { + say 'deleted.' + } + else + { + say " deletion failed: $!"; + } + } } } - print "\r\nfound $delcounter duplicate file versions. \r\n"; + say "\r\nfound $delcounter duplicate file versions."; } sub exist_newer_file @@ -80,12 +87,11 @@ sub exist_newer_file } else { - $version_regex = '['. ($fileparts[2] + 1) .'...9]'; + $version_regex = '['. ($fileparts[2] + 1) .'-9]'; } - my $filefinder_regex = "$fileparts[0].$fileparts[1].$version_regex.$fileparts[3]"; - - my @version_files = File::Find::Rule->file->name( $filefinder_regex )->maxdepth(1)->in( dirname($original_file) ); + my $filefinder_regex = "$fileparts[0]\\.$fileparts[1]\\.$version_regex\\.$fileparts[3]"; + my @version_files = File::Find::Rule->file->name( qr/$filefinder_regex/i )->in( dirname($original_file) ); if ( scalar @version_files ) { @@ -98,18 +104,18 @@ sub exist_newer_file sub show_help { - print $PROGRAM . ' - version ' . $VERSION . "\r\n"; - print "published under BSD 3 - Clause License \r\n"; - print "Copyright(c) 2019 René Wagner\r\n"; - print "https://www.codewolke.net/silkypix-helper/ \r\n"; - print "\r\n"; - print "Deletes Silkypix Sidecar files when newer versions of the files are available.\r\n"; - print "This usually happens when a file is opened in a newer version of Silkypix, as the sidecar files are version specific.\r\n"; - print "\r\n"; - print "commandline parameters:\r\n"; - print "duplicate_sidecar_cleaner.pl - list duplicate sidecar file versions in current working directory and subfolders\r\n"; - print "duplicate_sidecar_cleaner.pl -d - delete duplicate sidecar file versions in given directory and subfolders\r\n"; - print "duplicate_sidecar_cleaner.pl <folder> - list duplicate sidecar file versions in given directory and subfolders\r\n"; - print "duplicate_sidecar_cleaner.pl -d <folder> - delete duplicate sidecar file versions in given directory and subfolders\r\n"; - print "duplicate_sidecar_cleaner.pl -h - show this help\r\n"; + say $PROGRAM . ' - version ' . $VERSION; + say 'published under BSD 3 - Clause License'; + say 'Copyright(c) 2019 René Wagner'; + say 'https://www.codewolke.net/silkypix-helper/'; + say ''; + say 'Deletes Silkypix Sidecar files when newer versions of the files are available.'; + say 'This usually happens when a file is opened in a newer version of Silkypix, as the sidecar files are version specific.'; + say ''; + say 'commandline parameters:'; + say 'duplicate_sidecar_cleaner.pl - list duplicate sidecar file versions in current working directory and subfolders'; + say 'duplicate_sidecar_cleaner.pl -d - delete duplicate sidecar file versions in given directory and subfolders'; + say 'duplicate_sidecar_cleaner.pl <folder> - list duplicate sidecar file versions in given directory and subfolders'; + say 'duplicate_sidecar_cleaner.pl -d <folder> - delete duplicate sidecar file versions in given directory and subfolders'; + say 'duplicate_sidecar_cleaner.pl -h - show this help'; } diff --git a/orphaned_sidecar_cleaner.pl b/orphaned_sidecar_cleaner.pl @@ -5,13 +5,14 @@ use warnings; use strict; +use feature qw(say); use Cwd; use File::Basename; use File::Find::Rule; use File::Find; use Switch; -my $VERSION = '0.1'; +my $VERSION = '0.2'; my $PROGRAM = 'Orphaned Sidecar Cleaner'; # parse commandline args @@ -38,28 +39,34 @@ sub main my ( $dir, $delete ) = @_; my ( $delcounter ) = 0; - print "working directory: $delete_dir \r\n"; - print 'action : '. ($delete_flag ? 'delete' : 'list only') . "\r\n \r\n"; - print "files with missing raw:\r\n"; + say "working directory: $delete_dir"; + say 'action : '. ($delete_flag ? 'delete' : 'list only') ."\r\n"; + say 'files with missing raw:'; # alle Dateien in allen Unterordnern *.spd *.spf suchen - my @files = File::Find::Rule->file->name( '*.spd', '*.spf' )->in( $dir ); + my @files = File::Find::Rule->file->name( qr/\.sp(d|f)$/i )->in( $dir ); foreach my $file ( @files ) { if ( ! exists_raw_filename($file) ) { - print $file .'...raw file not found!'; + print $file .'...'; $delcounter++; if ( $delete ) { - unlink $file or warn " Deletion failed: $!"; - } - print "\r\n"; + if ( unlink $file ) + { + say 'deleted.'; + } + else + { + say " deletion failed: $!"; + } + } } } - print "\r\nfound $delcounter orphaned sidecar files found.\r\n"; + say "\r\nfound $delcounter orphaned sidecar files found."; } sub exists_raw_filename @@ -78,17 +85,17 @@ sub exists_raw_filename sub show_help { - print $PROGRAM . ' - version ' . $VERSION . "\r\n"; - print "published under BSD 3 - Clause License \r\n"; - print "Copyright(c) 2019 René Wagner\r\n"; - print "https://www.codewolke.net/silkypix-helper/ \r\n"; - print "\r\n"; - print "Deletes Silkypix Sidecar files when corresponding RAW files are missing.\r\n"; - print "\r\n"; - print "commandline parameters:\r\n"; - print "orphaned_sidecar_cleaner.pl - list orphaned sidecar file in current working directory and subfolders\r\n"; - print "orphaned_sidecar_cleaner.pl -d - delete orphaned sidecar file in current working directory and subfolders\r\n"; - print "orphaned_sidecar_cleaner.pl <folder> - list orphaned sidecar file in given directory and subfolders\r\n"; - print "orphaned_sidecar_cleaner.pl -d <folder> - delete orphaned sidecar file in given directory and subfolders\r\n"; - print "orphaned_sidecar_cleaner.pl -h - show this help\r\n"; + say $PROGRAM . ' - version ' . $VERSION; + say 'published under BSD 3 - Clause License'; + say 'Copyright(c) 2019 René Wagner'; + say 'https://www.codewolke.net/silkypix-helper/ '; + say ''; + say 'Deletes Silkypix Sidecar files when corresponding RAW files are missing.'; + say ''; + say 'commandline parameters:'; + say 'orphaned_sidecar_cleaner.pl - list orphaned sidecar file in current working directory and subfolders'; + say 'orphaned_sidecar_cleaner.pl -d - delete orphaned sidecar file in current working directory and subfolders'; + say 'orphaned_sidecar_cleaner.pl <folder> - list orphaned sidecar file in given directory and subfolders'; + say 'orphaned_sidecar_cleaner.pl -d <folder> - delete orphaned sidecar file in given directory and subfolders'; + say 'orphaned_sidecar_cleaner.pl -h - show this help'; }