You FE must be very primitive if it can't match the media to the romname. If so, maybe you should look for another FE? What FE are you using anyway?
PBJ is right - renaming all the rom files (or the media files, the names should match) will break everything, except maybe your brute-force work-around.
Most modern FEs can read/parse the xml to allow this to happen seamlessly. Those that don't (eg older FEs don't work with modern mame xml formats) should be able to read a DAT file with essentially the same information. Any FE from the past 20 years should be able to do this.
In Mamewah, for example, you would choose to create game lists according to "rom_folder_vs_dat_file", which would then give you the game description in long form eg "Donkey Kong", and match that to the romname eg "dkong" for media, launching, etc.
I think it would be easier to make a DAT file by hand than to rename all the roms. I've done it a few times for small sets.
Another way about it is to use a utility like "Romlister" which can parse the xml files and rom sets to create game lists for use in a bunch of different front ends, all without renaming any roms.
https://www.waste.org/~winkles/ROMLister/Maybe you need some advice specific to the FE you are using... oh yeah, what is it?