in reply to Re^2: Removing characters in a file name
in thread Removing characters in a file name
for my $file (glob '*.mp4') { if ($file =~ /^[^0-9]*([0-9]+)[^0-9]*.mp4/) { rename $file, "[Books] $1.mp4" or die "$file: $!"; } elsif ($file =~ /[0-9].*4/) { die "Several numbers found in $file."; } else { die "No number found in $file." } }
You can replace the second and third die with a warn if you just want to skip the files that weren't renamed.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Removing characters in a file name
by andy2020 (Initiate) on Apr 23, 2020 at 02:42 UTC | |
by jwkrahn (Abbot) on Apr 23, 2020 at 03:11 UTC | |
by andy2020 (Initiate) on Apr 23, 2020 at 03:28 UTC |