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 633da6a01f4f9b8787f51f35ce06eb7f552bb480
parent d452d3773fb23df79a7573dc26d379eb9713a0b4
Author: René Wagner <apollo@rw-net.de>
Date:   Mon, 30 Sep 2019 18:14:06 +0200

implement jpegdivider #0000017

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"; +}