From 1806d9f01fc4a0746d2f9df42ef1ee6827c7fa09 Mon Sep 17 00:00:00 2001 From: Stephan Barth Date: Mon, 29 Jul 2024 15:38:46 +0200 Subject: [PATCH] fix(utils): Verboseparameter -v hinzugefuegt; rekursives makedir; genauere Meldungen. --- utils/renamer.pl | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/utils/renamer.pl b/utils/renamer.pl index 04ee4bbd3..176eab9c5 100755 --- a/utils/renamer.pl +++ b/utils/renamer.pl @@ -3,21 +3,36 @@ use strict; use warnings; +my %progparams = (); +while(@ARGV > 3) { + my $p = shift @ARGV; + $progparams{$p} = 1; +} + +my $verbose = $progparams{"-v"}; + my ($fromdir, $renamefile, $todir) = @ARGV; sub usage { - die "usage: $0 [fromdir] [renamefile] [todir]\n + my $msg = shift; + if($msg) { $msg="\n$msg\n" } else {$msg=''} + die "usage: $0 {options} [fromdir] [renamefile] [todir]\n takes files from [fromdir], renames according to the json-map in [renamefile] and writes the files to [todir]. - old filenames are used as keys; new filenames as value\n"; + old filenames are used as keys; new filenames as value. + + Options: + -v verbose output +$msg"; } -usage() unless $fromdir and $renamefile and $todir; -usage() unless -d $fromdir; -usage() unless -f $renamefile; +usage("missing parameters: fromdir renamefile todir needed") unless $fromdir and $renamefile and $todir; +usage("fromdir is not a directory") unless -d $fromdir; +usage("renamefile is not given") unless -f $renamefile; -mkdir $todir; +#mkdir $todir; +system("mkdir", '-p', $todir); my %did = (); my %params = (); @@ -69,7 +84,7 @@ for my $to (keys %toRename) { } for(@errNex) { - warn "Could not rename non-existent file: $_\n"; + warn "Could not rename non-existent file: $_\n" if $verbose; } die "Syntax error in [renamefile], could not process everything!" if $core!~m#^[\s*,]*$#; @@ -78,7 +93,7 @@ my $dh = undef; opendir($dh, $fromdir) or die "Could not read dir '$fromdir', because: $!"; while(my $filename = readdir($dh)) { next if $filename=~m#^\.\.?$#; - warn "Did not touch not mentioned file '$filename'\n" unless $did{$filename}; + warn "Did not touch not mentioned file '$filename'\n" unless $did{$filename} or not $verbose; }