Files
scripts/Perl rename dirs and merge/rendir.pl
2024-10-14 00:08:40 +02:00

32 lines
581 B
Perl

#!/bin/perl
use File::Copy;
opendir (in,".");
@a=readdir(in);
close in;
foreach (@a) {
chomp;
if (-d $_) {
if ($_ =~ /\([0-9]+\)$/) {
print "alt: $_\n";
($new,$no) = $_ =~ /(.*)(\([0-9]+\))$/;
$new =~ s/\s+$//;
print "neu: $new\n";
$alt=$_;
opendir (mv,"$alt");
@b=readdir(mv);
close mv;
foreach (@b) {
next if (-d $_);
($oldfile,$ext) = $_ =~/(.*)\.(.*)$/;
$newfile=$oldfile.$no.".".$ext;
print "mv '$alt\\$_' '$new\\$newfile'\n";
move ("$alt\\$_", "$new\\$newfile");
}
}
}
print "\n";
}