Renumber sequentially restarting for each folder

Hi I have a set of about 1000 folders. each folder has 8 files. 4 of the folders are jpg pictures, 4 are the related sidecar files.

Example
folder name:antenna:
gsjkas.jpg & gsjkas.txt
bxbb.jpg & bxbb.txt etc.
folder name beak:
blahblah.jpg & blahblah.txt
xxxx.jpg & xxxx.txt
aaa.jpg & aaa.txt etc.

I want to rename each file and its sidecar to the folder name plus a sequence number from 1 to 4.
in the above example, the files would become

folder name:antenna:
antenna1.jpg & antenna1.txt
antenna2.jpg & antenna2.txt
antenna3.jpg & antenna3.txt etc.
folder name beak:
beak1.jpg & beak1.txt
beak2.jpg & beak2.txt
beak3.jpg & beak3.txt etc.

I have figured out how to rename the files except that i cant figure out how to restart the sequence number each time there is a new folder.
The rename i am using is:
Old name: (.).(.)
New name: {parent1}.\2
the choices are: regular expression, auto rename, enable file info fields, rename matching filenames,and sequential numbering. i have tried checking the rename files in selected sub-folders, but that does not seem to change anything.
All help appreciated.
Thank you!

You'll probably need a script to do that.

This one is very similar and should work as a starting point at least: Number Within Sub-Folders

Leo, thank you very much! it was exactly what i needed. You are one of Dopus most important assets, because the program is so complex that it is really wonderful to have someone guide you through. plus you answer quickly. when i compare dopus to lightroom, this quick, reliable and accurate response is a significant difference - lots of other differences too of course.