Списание этого с макушки моей головы, но здесь идет.Мы собираемся использовать os.path.walk для рекурсивного перехода в ваши каталоги и minidom для выполнения анализа.
import os
from xml.dom import minidom
# opens a given info.xml file and prints out "Path"'s contents
def parseInfoXML(filename):
doc = minidom.parse(filename)
for fileNode in doc.getElementsByTagName("File"):
# warning: we assume the existence of a Path node, and that it contains a Text node
print fileNode.getElementsByTagName("Path")[0].childNodes[0].data
doc.unlink()
def checkDirForInfoXML(arg, dirname, names):
if "info.xml" in names:
parseInfoXML(os.path.join(dirname, "info.xml"))
# recursively walk the directory tree, calling our visitor function to check for info.xml in each dir
# this will include packs as well, so be sure that there's no info.xml in there
os.path.walk("/var/packs" , checkDirForInfoXML, None)
Не самый эффективный способ выполнить это, я уверен, ноЯ сделаю, если вы не ожидаете ошибок / что угодно.