python create a script that looks through weapons.meta files that are within folders in…
- User
python create a script that looks through weapons.meta files that are within folders in a base folder the open the weapons.meta and find the text WEAPON_ and append the WEAPON_name to a txt document
here is a an example of what the weapons.meta file looks like WEAPON_AK971
In this example I was want it to return and add WEAPON_AK971 to the txt document
don't use import xml.etree.ElementTree as ET
- Assistant
To create a script that searches for
weapons.metafiles, reads the file, and appends theWEAPON_names to a text document, you can use the following code snippet. Note that this doesn't usexml.etree.ElementTree.import os import re def find_weapons(base_folder): weapon_names = [] for root, _, files in os.walk(base_folder): for file in files: if file == "weapons.meta": with open(os.path.join(root, file), "r") as f: content = f.read() weapon_names.extend(re.findall(r'<Name>(WEAPON_\w+)</Name>', content)) return weapon_names def main(): base_folder = "path/to/base/folder" output_file = "weapons.txt" weapon_names = find_weapons(base_folder) with open(output_file, "w") as f: for weapon in weapon_names: f.write(weapon + "\n") print(f"Weapon names have been written to {output_file}") if __name__ == "__main__": main()This script first goes through the base folder to find all
weapons.metafiles. Then it reads the content of the files and extracts the weapon names using a regular expression.