Incrementing number by regexp

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
LittleBiG
Posts: 1848
Joined: 08 Apr 2011 12:57
Location: Win10x64

Incrementing number by regexp

Post 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?

LittleBiG
Posts: 1848
Joined: 08 Apr 2011 12:57
Location: Win10x64

Re: Incrementing number by regexp

Post 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);

Post Reply