import xml.etree.ElementTree as ET from dataclasses import dataclass from typing import List, Optional from pathlib import Path @dataclass class SourcedFile: layer_name: str subfolder: Optional[str] files: List[str] def read_psc_file(psc_file: Path) -> List[SourcedFile]: tree = ET.parse(psc_file) root = tree.getroot() layers = root.findall(".//Layer") layer_info_list: List[SourcedFile] = [] for layer in layers: layer_name = layer.attrib.get("Name") subfolder = layer.attrib.get("SubFolder") # Scripts-Filenames scripts = layer.find("Scripts") script_names = [] if scripts is not None: for filename in scripts.findall("Filename"): name = filename.attrib.get("Name") if name: script_names.append(name) layer_info_list.append( SourcedFile(layer_name=layer_name, subfolder=subfolder, files=script_names) ) return layer_info_list def get_all_psc_files(root_path: Path) -> list[Path]: return [path for path in root_path.rglob("*.psc")] if __name__ == "__main__": test = get_all_psc_files( Path( r"H:\janus-engineering-customers\KSB_Frankenthal\custom\library\machine\installed_machines\ksb_pe_grob_g550_sone\postprocessor" ) ) print(test) for pp in test: read_psc_file(pp)