# Collection of code snippets by Arne Vajhøj 
# (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import sys
from os.path import isdir,join
from os import listdir
from xml.dom.minidom import Document
from xml.dom.ext import PrettyPrint
def recurse(doc, currnode, fulldir, shortdir):
    direlm = doc.createElement('dir')
    direlm.setAttribute('name', shortdir)
    currnode.appendChild(direlm)
    for shortfnm in listdir(fulldir):
        fullfnm = join(fulldir, shortfnm)
        if isdir(fullfnm):
            recurse(doc, direlm, fullfnm, shortfnm)
        else:
            fileelm = doc.createElement('file')
            fileelm.setAttribute('name', shortfnm)
            direlm.appendChild(fileelm)
doc = Document()
recurse(doc, doc, sys.argv[1], sys.argv[1])
PrettyPrint(doc)
