Page 1 of 1

Incrementing number by regexp

Posted: 02 Oct 2015 12:11
by LittleBiG
I have to rename files. If there is a number at the end of the filename it has to be incremented. If there weren't any numbers at the end, "1" should be added to the filename.
test -> test1
test5 -> test6
test65a -> test65a1

My solution works:

Code: Select all

renameitem(regexreplace("<curbase>","^(.*?)(\d*)$","$1") . regexreplace("<curbase>","^(.*?)(\d*)$","$2")+1);
But is there any other, rather more elegant way to achieve this? Preferably with the "rename r," command, which could work on more files at once?

Re: Incrementing number by regexp

Posted: 07 Oct 2015 10:09
by LittleBiG
This is still not with rename command, but a bit shorter than the last solution.

Code: Select all

renameitem(eval(regexreplace("<curbase>","^(.*?)(\d*)$","'$1' . ($2+1)")),,1);