#Replace game name with the rom name, github: https://github.com/dsoft20
#This script takes the gamelist.xml generated by the Universal XML-Scraper
#and replace the scraped name field (<name>) with the rom name
#		<path>./Game name (Europe).zip</path>
#		<name>Game name</name>
#							TO
#		<path>./Game name (Europe).zip</path>
#		<name>Game name (Europe)</name>
#
#WINDOWS: place the file on \\raspberry\configs\all\emulationstation\gamelists\
#		  run the script via python rm.py
#		  
#RETROPIE: place the file in /home/pi/.emulationstation/gamelists/
#		   run the script via python rm.py
#		   
import sys, os, time, io

def parse(directory):

	romFileName = ""
	gameName = ""
	tempName = ""
	entries = []
	
	#toreplace contains string that have to be removed from the rom file name
	#please add unlisted rom extensions (eg: .gbc)
	toreplace = ["./",".zip","<path>","</path>"]
	index = 0

	if os.path.exists(".//"+directory+"gamelist.xml") == False: #check if gamelist.xml exists, if not return
		print("FILE DOES NOT EXISTS")
		return

	print("READING gamelist.xml")

	#read gamelist.xml in this directory
	file = io.open(".//"+directory+"gamelist.xml", "r",encoding='utf-8')
	entries = file.read().splitlines()
	file.close()

	#make a backup
	file = io.open(".//"+directory+"gamelist.xml.bck","w",encoding='utf-8')
	while index<len(entries):
		file.write(entries[index]+"\n")
		index+=1
	file.close()

	index = 0

	#check the file to its end and do stuff
	while index<len(entries):
		if "<path>" in entries[index]:

			tempName = entries[index]
			print("Found:" + tempName)

			#remove spaces before and after filename
			tempName = tempName.rstrip()
			tempName = tempName.lstrip()

			#remove strings as per toremove array
			for i in range(0,len(toreplace)):
				tempName = tempName.replace(toreplace[i],"")

			tempName = "\t\t<name>"+tempName+"</name>"

			entries[index+1] = tempName
			print("Name edited: " + tempName)

		index = index+1

	index = 0

	#write the updated gamelist.xml to disk
	file = io.open(".//"+directory+"gamelist.xml", "w",encoding='utf-8')
	print("writing updated gamelist.xml")
	while index<len(entries):
		file.write(entries[index]+"\n")
		index+=1

	file.close()
	return

def main():

	#systems list, please add unlisted systems
	systems = ["amstradcpc","atari2600","atari7800","atarilynx","coleco","fba","fbs","fds","gamegear","gb","gba","gbc","genesis","mame-libretro","mame-mame4all","mastersystem","megadrive","msx","n64","neogeo","nes","ngp","ngpc","pcengine","psx","sega32x","segacd","sg-1000","snes","vectrex","wonderswan","wonderswancolor","zxspectrum"]

	if os.path.exists(".//gamelist.xml"): #if gamelist.xml exists on current directory then parse &  edit only that, if not search for systems directory and parse their gamelist.xml
		print("Parsing local gamelist.xml")
		parse(".//")
	else:
		for i in range(0,len(systems)):
			print("Parsing "+ systems[i])
			parse(".//"+systems[i]+"//")

	print("DONE!")
	return

if __name__ == "__main__": main()

Create rm.py