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

Merge branch 'jpegdivider'

Diffstat:
MREADME.md | 4++++
Ajpegdivider.pl | 77+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 81 insertions(+), 0 deletions(-)

diff --git a/README.md b/README.md @@ -10,10 +10,14 @@ The following perl modules are required for running the scripts. - File::Basename - File::Find::Rule - File::Find +- File::Copy; - Switch ## description +### jpeg divider +Moves all jpeg files (suffixes .jpg and .jpeg) in a folder to the subfolder JPEG. + ### orphaned sidecar cleaner Deletes all sidecar files in the given directory or alternatively in the current working directory when the associated raw file is missing. diff --git a/jpegdivider.pl b/jpegdivider.pl @@ -0,0 +1,77 @@ +#!/usr/bin/perl +# Copyright(c) René Wagner 2019 +# published under BSD 3-Clause License +# https://www.codewolke.net/silkypix-helper/ + +use warnings; +use strict; +use Cwd; +use File::Basename; +use File::Find; +use File::Find::Rule; +use File::Copy; +use Switch; + +my $VERSION = '0.2'; +my $PROGRAM = 'JpegDivider'; + +my $SUBFOLDER = 'JPEG'; +# parse commandline args +# last dir will win +my $work_dir = getcwd; + +foreach my $arg ( @ARGV ) +{ + switch ( $arg ) + { + case '-h' { show_help(); exit; } + else { if ( -d $arg ) { $work_dir = $arg } } + } +} + +main($work_dir); + +exit 0; + +sub main +{ + my ( $dir ) = @_; + my ( $move_counter ) = 0; + + print "working directory: $dir \r\n"; + print "moving jpeg files to subfolder:\r\n"; + + my $destination_dir = "$dir\/$SUBFOLDER"; + + if ( ! -d $destination_dir ) + { + 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 ); + + foreach my $file ( @files ) + { + print $file .'...'; + $move_counter++; + move($file, "$destination_dir\/".basename($file) ) or warn " move failed: $!"; + print "\r\n"; + } + + print "\r\nmoved $move_counter jpeg files to subfolder.\r\n"; +} + +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"; +}