fix(utils): Verboseparameter -v hinzugefuegt; rekursives makedir; genauere Meldungen.

This commit is contained in:
Stephan Barth 2024-07-29 15:38:46 +02:00
parent 3bc3acf38c
commit 1806d9f01f

View File

@ -3,21 +3,36 @@
use strict; use strict;
use warnings; use warnings;
my %progparams = ();
while(@ARGV > 3) {
my $p = shift @ARGV;
$progparams{$p} = 1;
}
my $verbose = $progparams{"-v"};
my ($fromdir, $renamefile, $todir) = @ARGV; my ($fromdir, $renamefile, $todir) = @ARGV;
sub usage { 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 takes files from [fromdir], renames according to the json-map in
[renamefile] and writes the files to [todir]. [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("missing parameters: fromdir renamefile todir needed") unless $fromdir and $renamefile and $todir;
usage() unless -d $fromdir; usage("fromdir is not a directory") unless -d $fromdir;
usage() unless -f $renamefile; usage("renamefile is not given") unless -f $renamefile;
mkdir $todir; #mkdir $todir;
system("mkdir", '-p', $todir);
my %did = (); my %did = ();
my %params = (); my %params = ();
@ -69,7 +84,7 @@ for my $to (keys %toRename) {
} }
for(@errNex) { 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*,]*$#; 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: $!"; opendir($dh, $fromdir) or die "Could not read dir '$fromdir', because: $!";
while(my $filename = readdir($dh)) { while(my $filename = readdir($dh)) {
next if $filename=~m#^\.\.?$#; 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;
} }