How to swap tag path in reference tags used for simulation?

Hi
I am struggling with the syntax to make a script which would loop through all reference tags in the folder and replace their path from OPC to the memory tags path.
If you could please advise me on the syntax?

ps. when i tried to use reference tags with 1 folder with opc tags and 1 folder with the simulation memory tags (with the same names as OPC tags) and then change the folder name to point the reference tags to either opc or simulation folder i end up having problems. I had to restart all tags from the reference folder to see the values but i guess i was using reference tags wrong hence my attempt now write to tag path property