Increment Number in Filename

I would like to rename a single filename e.g. "00 Test" or "000 Test" by incrementing the numeric part of the filename by 10 to e.g. "10 Test" or "110 Test". Any advice gratefully received.

The DO builtin rename is not capable of detecting a number and increasing it, as far as I can remember.
The script command "RenameEx" might work, but DO v11 is required for this.

If RenameEx doesn't work, you can do this in Dynamic Renamer.

It consists of two chained transformations:

-/(\d+)/$1 + 10/e   -z3

the first increments the first found number by 10, the optional second transformations zero pads the number to the original 3 places.

The first transformation is a Perl substitution, where the replacement is an expression evaluated on the matched digits.

Here's a small rename script which does it and doesn't require you to install anything else:

Inside the zip is a .ORP file, which is a Rename Preset you can import via the File > Import... menu item at the top-left of the Rename (Advanced) dialog:

Add (532 Bytes)

Script code in text form in case it's easier to paste into the dialog (remember to set both the "old name" and "new name" fields to "*" as well):

@script vbscript Function OnGetNewName(ByRef getNewNameData) Set re = new RegExp re.Pattern = "^([^0-9]*)([0-9]+)(.*)$" If (re.Test(getNewNameData.newname)) Then OrigNumber = re.Replace(getNewNameData.newname, "$2") NewNumber = CStr(OrigNumber + 10) Do While (Len(NewNumber) < Len(OrigNumber)) NewNumber = "0" & NewNumber Loop OnGetNewName = re.Replace(getNewNameData.newname, "$1" & NewNumber & "$3") End If End Function

How it works: It uses a regular expression to extract the number, adds 10 to it, pads it to the original length, then uses the same regular expression to insert the new number back into the name.

Thanks Leo, that works like a charm. (And thanks also MrC - I'm afraid Perl is out of my depth)

And now for a dumb question. I want to add to your VBscript to send a downarrow keystroke followed by an uparrow keystroke. This will move the focus back to the renamed file so that if I want to increment it more than once I can conveniently do so. How might I do that?



You can prevent the file being deselected in the first place. Edit the Rename button and add @nodeselect to it if it is missing.


Rename ADVANCED @nodeselect


Rename PRESET="Add 10" @nodeselect

Thanks very much Leo I would never have worked that out. Cheers, Mike