' 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) 
Imports System
Imports System.IO
Imports System.Xml

Public Class MyUtilities
    Public Shared Function DirToXml(Dir As String, Pat As String) As XmlDocument
        Dim doc As XmlDocument = New XmlDocument 
        Dim root As XmlElement = doc.CreateElement("IMAGES")
        doc.AppendChild(root)
        Dim files As String() = Directory.GetFiles(Dir, Pat)
        For Each f As String In files
            Dim elm As XmlElement = doc.CreateElement("IMAGE")
            elm.AppendChild(doc.CreateTextNode((New FileInfo(f)).Name))
            root.AppendChild(elm)
        Next
        DirToXml = doc
    End Function
End Class

Module Main
    Sub Main()
        Dim res As XmlDocument = MyUtilities.DirToXml("C:\", "*.bat")
        res.Save(Console.Out)
    End Sub
End Module
