Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import xml.etree.ElementTree as ET
- import xml.dom.minidom
- #This script requires all modded files to be in a folder matching their rockstar counter-part
- #Change the levels/rdr3/props/vegetation/ and hd_0/hd/levels/rdr3/props/vegetation/ to wherever it needs to be
- # Define the directory and xml file paths
- directory_path = "D:\\Games\\Red Dead Redemption 2\\MODWORKINGFOLDER\\###DONE\\Mega Pack\\lml\\Upscaled Textures\\Upscaled Documents"
- xml_file_path = "D:\\Games\\Red Dead Redemption 2\\MODWORKINGFOLDER\\###DONE\\install replace.xml"
- output_file_path = os.path.join(directory_path, "install python.xml")
- # Parse the XML file
- tree = ET.parse(xml_file_path)
- root = tree.getroot()
- # Find the 'Resources' tag
- resources_tag = root.find('Resources')
- # Traverse the directory structure
- for folder_name, subfolders, filenames in os.walk(directory_path):
- # Get the relative folder name
- relative_folder_name = os.path.relpath(folder_name, directory_path)
- for filename in filenames:
- # Skip .py, .xml, and .txt files
- if filename.endswith(('.py', '.xml', '.txt', '.bak')):
- continue
- # Create a new 'Resource' tag
- resource_tag = ET.SubElement(resources_tag, 'Resource')
- # Create a new 'FileReplacement' tag
- file_replacement_tag = ET.SubElement(resource_tag, 'FileReplacement')
- # Determine the 'GamePath' and 'FilePath' based on the folder name
- if relative_folder_name.startswith("hd"):
- game_path = f"platform:/hd/levels/rdr3/props/vegetation/{relative_folder_name[2:]}/{filename}" #old unused code for this instance
- file_path = f"{relative_folder_name[2:]}/{filename}"
- else:
- game_path = f"platform:textures/textures/ui/{relative_folder_name}/{filename}" #correct format??
- file_path = f"{relative_folder_name}/{filename}"
- # Create the 'GamePath' and 'FilePath' tags
- game_path_tag = ET.SubElement(file_replacement_tag, 'GamePath')
- game_path_tag.text = game_path
- file_path_tag = ET.SubElement(file_replacement_tag, 'FilePath')
- file_path_tag.text = file_path
- # Convert the ElementTree to a string
- xml_string = ET.tostring(root, encoding='utf-8')
- # Parse the string to a minidom object
- dom = xml.dom.minidom.parseString(xml_string)
- # Pretty print the XML to the output file
- with open(output_file_path, 'w') as f:
- f.write(dom.toprettyxml(indent=" "))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement