Create Directory Structure From XML File with

One of my assignments at GE Healthcare was to recreate a directory structure from a an already created XML file. This is what I came up with.

Make sure you put:
Imports System.IO
Imports System.Xml
At the top of your class.

Hope it helps someone.

Private Sub button4_Click(ByVal sender As Object, ByVal e As EventArgs)
     Dim document As New XmlDocument()
     CreateDirectories("c:\temp\test\", document.SelectNodes("root/folder"))
End Sub
Private Sub CreateDirectories(ByVal directory As String, ByVal nodes As XmlNodeList)
     For Each node As XmlNode In nodes
         Dim directoryName As String = node.Attributes("name").Value
         Dim fullPath As String = directory + directoryName + "\"
         If node.HasChildNodes Then
             CreateDirectories(fullPath, node.ChildNodes)
         End If
End Sub

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: