create an a python script that looks through all the weapons.meta file within a folder…
- User
create an a python script that looks through all the weapons.meta file within a folder creates a document with all the values within
the base folder path is T:\Fivem Related\Alpha Dev\stream_weapons\metas\addon
within the addon folder you've got a folder for every weapon and inside that folder is where you will find the weapons.meta files
the weapons.meta file contains a few tags so you only want to get the one that is directly after
- Assistant
First, you need to import the necessary modules and libraries. You will need the
osmodule for interacting with the file system, theremodule for regular expressions, and thexml.etree.ElementTreemodule for XML processing.Here is a script that achieves what you requested:
import os import re import xml.etree.ElementTree as ET # Define the base folder path base_path = "T:\Fivem Related\Alpha Dev\stream_weapons\metas\addon" # Define the output file output_file = "weapon_names.txt" # Initialize an empty list to store weapon names weapon_names = [] # Iterate through the directories and files within the base path for root, dirs, files in os.walk(base_path): for file in files: _, ext = os.path.splitext(file) if ext == ".meta": # Full path to the .meta file meta_filepath = os.path.join(root, file) # Parse the .meta file tree = ET.parse(meta_filepath) root_elem = tree.getroot() # Find the CWeaponInfo tag weapon_info_tag = root_elem.find(".//Item[@type='CWeaponInfo']") if weapon_info_tag is not None: # Find the Name tag within the CWeaponInfo tag name_tag = weapon_info_tag.find(".//Name") if name_tag is not None: # Get the text within the Name tag and add it to the list weapon_names.append(name_tag.text) # Write the weapon names to the output file with open(output_file, "w") as f: for name in weapon_names: f.write(name + "\n") print(f"Weapon names have been saved to {output_file}")