I need to search in a parent folder all files that are config.xml and in those files replace one string in another. (from this-is to where-as)
I need to search in a parent folder all files that are config.xml and in those files replace one string in another. (from this-is to where-as)
import os
parent_folder_path = 'somepath/parent_folder'
for eachFile in os.listdir(parent_folder_path):if eachFile.endswith('.xml'):newfilePath = parent_folder_path+'/'+eachFilefile = open(newfilePath, 'r')xml = file.read()file.close()xml = xml.replace('thing to replace', 'with content')file = open(newfilePath, 'w')file.write(str(xml))file.close()
Hope this is what you are looking for.