I have a lot of files I\'m trying to rename, I tried to make a regular expression to match them, but even that I got stuck on the files are named like:
<
Run two commands, in this order:
$ rename 's/File Name (\d)$/File Name 0$1/' *
$ rename 's/File Name (\d\d)$/File Name 0$1/' *
First one renames everything less than 10 and prepends a zero. The second one renames everything less than 100 and prepends a zero. The result should be three digits for all filenames.
you could do something using perl or ruby.
put all this files in the same directory
dirlisting = DIR.entries('.')
dirListing.each do |file|
num = file.match(/\d+$/).to_i
if num < 100
find the position where start the number, with index and inject the 0 there.
end
end
use strict;
use File::Copy;
my @files = glob 'File*Name*';
foreach my $filename (@files) {
if ($filename =~ m`^.*File.*Name.*?(\d+)`) {
my $number = $1;
next if ($number > 99);
rename $filename, sprintf("FileName%03d",$number);
}
}