PS AS Batch that saves in multiple folders based on inputfol

Hi! :smiley:

I´m trying too make an AS that takes an inputfolder with subfolders containing files, making duplicates of the folders in another location,
do some actions in Photoshop and then rename and save the files in the appropriate folder.

Eg a file named “104.tif” resides in a folder called “Brenna 3456”, file should be renamed “3456.tif” and saved in same folder name in new location.
In subfolders containing multiple files, I want them to be assigned a serial like “3769_01.tif”, “3769_02.tif”, “3769_03.tif”.
See fig for visual

Hope to at least get some tip too put me in the right direction, in advance thank you…

[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

I have manage most of my goals for the script, but there are still some issues needed to be solved, mainly about path to folders etc…
Remember that this is just part of the script and has some errors.