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

implements #0000018
default to list only mode and add -m commandline switch

Diffstat:
MREADME.md | 2+-
Mjpegdivider.pl | 40++++++++++++++++++++++++----------------
2 files changed, 25 insertions(+), 17 deletions(-)

diff --git a/README.md b/README.md @@ -10,7 +10,7 @@ The following perl modules are required for running the scripts. - File::Basename - File::Find::Rule - File::Find -- File::Copy; +- File::Copy - Switch ## description diff --git a/jpegdivider.pl b/jpegdivider.pl @@ -13,38 +13,41 @@ use File::Find::Rule; use File::Copy; use Switch; -my $VERSION = '0.2'; +my $VERSION = '0.3'; my $PROGRAM = 'JpegDivider'; my $SUBFOLDER = 'JPEG'; # parse commandline args # last dir will win my $work_dir = getcwd; +my $move_flag = 0; foreach my $arg ( @ARGV ) { switch ( $arg ) { case '-h' { show_help(); exit; } + case '-m' { $move_flag = 1; } else { if ( -d $arg ) { $work_dir = $arg } } } } -main($work_dir); +main($work_dir, $move_flag); exit 0; sub main { - my ( $dir ) = @_; - my ( $move_counter ) = 0; + my ( $dir, $move_flag ) = @_; + my $move_counter = 0; say "working directory: $dir"; - say "moving jpeg files to subfolder: $SUBFOLDER \r\n"; + say 'action : '. ($move_flag ? 'move' : 'list only'); + say "subfolder : $SUBFOLDER"; + say ''; my $destination_dir = "$dir\/$SUBFOLDER"; - - if ( ! -d $destination_dir ) + if ( $move_flag && ! -d $destination_dir ) { mkdir $destination_dir or die "Could not create destination dir $_ : $!"; } @@ -55,17 +58,20 @@ sub main { print $file .'...'; $move_counter++; - if ( move($file, $destination_dir. '/' .basename($file) ) ) - { - say "moved."; - } - else + if ( $move_flag ) { - say "move failed: $!"; + if ( move($file, $destination_dir. '/' .basename($file) ) ) + { + say "moved."; + } + else + { + say "move failed: $!"; + } } } - say "\r\nmoved $move_counter jpeg files to subfolder."; + say "\r\nfound $move_counter jpeg files to subfolder."; } sub show_help @@ -78,7 +84,9 @@ sub show_help 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 - list all jpeg files in the current working dir'; + say 'jpegdivider.pl -m - create a subfolder "JPEG" in the current working dir and move jpeg files in there'; + say 'jpegdivider.pl <folder> - list all jpeg files in the given directory'; + say 'jpegdivider.pl -m <folder> - create a subfolder "JPEG" in the given directory and move jpeg files in there'; say 'jpegdivider.pl -h - show this help'; }