Adding a set amount to the number part of a file name.

Would you like Bulk Rename Utility to offer new functionality? Post your comments here!

Adding a set amount to the number part of a file name.

Postby SeanMck » Tue Apr 28, 2020 11:20 pm

Say I have a set of photos with the following names and that, for the purposes of this question, they are sorted by name or date/time-taken.
homer-0001.jpeg
homer-0002.jpeg
homer-0003.jpeg
homer-0004.jpeg
homer-0004.DNG
homer-0004.RAW
homer-0005.jpeg
homer-0006.jpeg
homer-0006.RAW
homer-0007.jpeg
.
.
.
.
homer-0559.jpeg

Imagine I boobed and had acidentally changed the naming scheme that the camera uses such that the camera resets the count to zero everytime the memory card is removed, emptied and replaced rather than continuing from the last number used. The filenames of the next cardful will start at homer-0001.
If I want to save the photos in a common folder I need to offset the names of the second block of photos by 559 so that the first photo in the second block becomes homer-0560.jpeg.
As there are photos of the same name but differing file types I can not simply increment the number part, the same problem arises where photos have been deleted etc.
Previously I have, between the breaks in continuity, erased the number bit and incremented the replacement but it gets very tedious if a lot of photos have been deleted.
Am I missing the way to do it? If not is it possible that this option could be added?
Thanks
SeanMck
 
Posts: 2
Joined: Tue Apr 28, 2020 10:41 pm

Re: Adding a set amount to the number part of a file name.

Postby Ric » Fri May 01, 2020 3:34 pm

Cannot guarantee but it is highly likely that ExifTool could accomplish this quite easily.

Suggest SeanMck look at the EXIFTOOL utility. https://exiftool.org/
Ric
 
Posts: 10
Joined: Fri Apr 10, 2020 6:17 pm

Re: Adding a set amount to the number part of a file name.

Postby Ric » Fri May 01, 2020 6:40 pm

BRU has regular expressions so .....
There are a few examples online showing how to do arithmetic in regular expressions.
The reality is those examples are really showing arithmetic in a regular expression embedded in a line (or more) of Perl code.
Best I can tell arithmetic in regular expressions (pure regex) is not possible.

So, either the Javascript option in BRU, or alternatively learn and use Perl.
Ric
 
Posts: 10
Joined: Fri Apr 10, 2020 6:17 pm

Re: Adding a set amount to the number part of a file name.

Postby SeanMck » Tue May 19, 2020 4:07 pm

Ta Rick from memory exiftool on its own gives my laptop a headache BUT I think one of other programmes uses it. I will have a look at reg exp etc. thanks
SeanMck
 
Posts: 2
Joined: Tue Apr 28, 2020 10:41 pm

Re: Adding a set amount to the number part of a file name.

Postby RegexNinja » Fri May 29, 2020 1:01 am

If you have the paid version, javascript handles the math of adding 559.
Here's a generic javascript that increments any name ending with a digit.

if (/\d$/.test(name)) {
beg=name.replace(/^(.*?)\d+$/,'$1') //beg = BeginName
num=name.replace(/^.*?(\d*)$/,'$1') //num = EndDigits
xxx=num.length // .......................xxx = #digits in EndDigits (with LeadZeros)
sum=parseInt(num,10)+559 // ......... sum = EndDigits+559 (in decimal)
yyy=sum.toString().length // ........... yyy = #digits in sum (no LeadZeros)
zer='0'.repeat(Math.max(0,xxx-yyy)) //zer = LeadZeros (if needed)
newName=beg+zer+sum} // ............ BeginName + LeadZeros + Sum


LeadZeros are determined by OrigNames, some example results:
AnyName__1.jpg -----> AnyName__560.jpg
Name__000002.jpg --> Name__000561.jpg
homer-0003.jpeg ----> homer-0562.jpeg
homer-0004.jpeg ----> homer-0563.jpeg
homer-0004.DNG ----> homer-0563.DNG
homer-0004.RAW ----> homer-0563.RAW
homer-0005.jpeg ----> homer-0564.jpeg
RegexNinja
 
Posts: 134
Joined: Fri Feb 21, 2020 5:26 pm


Return to Suggestions