This repository has been archived on 2026-03-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
TP-BDD2/python/TP2.py
2022-03-05 21:48:39 +01:00

40 lines
1.1 KiB
Python

from os import listdir
from os.path import isdir, isfile
from xml.dom import minidom
doc = minidom.parse('../xml/TP1.xml')
dico = doc.getElementsByTagName('dictionary')[0]
def printDico(dico, past):
for child in dico.childNodes:
if child.nodeType == child.ELEMENT_NODE:
val = child.getAttribute('value')
if len(child.childNodes) == 0:
print(past + val)
else:
printDico(child, past + val + "-")
# printDico(dico,'')
def dirToXml(path, doc, el):
for elem in listdir(path):
path_ = path + "/" + elem
if isfile(path_):
node = doc.createElement("file")
node.attributes["name"] = elem
el.appendChild(node)
elif isdir(path_):
node = doc.createElement("dir")
node.attributes["name"] = elem
el.appendChild(node)
dirToXml(path_, doc, node)
root = minidom.Document()
xml = root.createElement('root')
root.appendChild(xml)
dirToXml("/", root, root.getElementsByTagName("root")[0])
print(root.toprettyxml())