#!python # -*- mode: python; Encoding: utf-8; coding: utf-8 -*- # Last updated: <2021/12/07 12:19:37 +0900> """ Read zip and get file list. Usage : python ThisScript.py INFILE Windows10 x64 21H1 + Python 3.9.7 64bit """ import zipfile import sys import xml.etree.ElementTree as ET target = "manifest.xml" # get input file name if len(sys.argv) < 2: print("Usage: python ThisScript.py INFILE") sys.exit() infile = sys.argv[1] print("Input File : %s\n" % infile) # Open zip zipf = zipfile.ZipFile(infile) # Get filenames if True: # use .namelist() names = zipf.namelist() else: # use .infolist() names = [] for info in zipf.infolist(): names.append(info.filename) # print filenames for fn in names: print(fn) print() if target in names: print("Found %s\n" % target) else: print("Not found %s\n" % target) sys.exit() # Read target file xmldata = zipf.read(target) # print(xmldata) # Parse xml root = ET.fromstring(xmldata) print("---- %s" % target) ET.dump(root) print() for i in root.iter(): print(i.tag, i.attrib, i.text) print() # get game tag elem = root.find("game") if elem is None: print("Not found tag") else: # get game tag text kind = elem.text if kind is None: print("") elif kind == "": print("") else: print("%s" % kind)