Rename files with numbering, reset if seperate folders

i have a button setup to open selected files or folders in the Advance Rename dialog, and then rename the files inside to their parent folder name with " pt " and then a seqential number at the end and then leave their original extension. if i select a set of files in a folder, they rename fine, but if i select a set of folders, it numbers all the files within as one set. how do i get it to restart the numbering every time it switches folders.

here is what its doing:

example folder A
file one
file two
example folder B
file one
file two
example folder C
file one
file two

the end up as:

example folder A
example folder A pt 1
example folder A pt 2
example folder B
example folder B pt 3
example folder B pt 4
example folder C
example folder C pt 5
example folder C pt 6

what i want is:

example folder A
example folder A pt 1
example folder A pt 2
example folder B
example folder B pt 1
example folder B pt 2
example folder C
example folder C pt 1
example folder C pt 2

That could be done with a rename script but I don't think there is an existing one which does exactly that.

It's quite similar to the Add a Unique Number while renaming script so that would be a good starting point, if you're familiar with VBScript. It'd have to be changed to reset its count for each directory.