Possible to 'sync' ratings between images with the same file name?

Following situation: i have two folders with images that have the same name. Some of them are newer edits of those files, but have no ratings. I would like to sync my old ratings over to the newer files, before i replace the old files. Having thousands of them, it would be very convenient to automate the process.
I guess, it is quite complicated and would require some sort of scripting.

This does that: