Dim xDoc As XDocument = XDocument.Load("Vehicle.xml")
Dim models = (From make In xDoc.Descendants("Make") _
Where make.Attribute("Name") = cbMake.Text _
From model In make.Descendants("Model").Elements() _
Where model.Name.LocalName.EndsWith(cbYear.Text) _
Select model).ToArray()
cbModel.Items.Clear()
cbModel.Items.AddRange(models)
Imports System.IO
Imports System.Xml.Linq
' The location of the start of the file structure
Dim startPath As String = "C:\Vehicle_DB"
Dim dirInfo As New DirectoryInfo(startPath)
Dim xDoc As New XDocument(New XDeclaration("1.0", "utf-8", "yes"), New XElement("Vehicle_DB"))
Dim root As XElement = xDoc.Root
For Each dir As DirectoryInfo In dirInfo.GetDirectories()
Dim newDir As New XElement(dir.Name)
Dim fileInfo() As FileInfo = dir.GetFiles()
For Each vicInfo As FileInfo In dir.GetFiles()
' Xml tag name can not start with numbers to put the date on the end
Dim vicName As String = vicInfo.Name.Substring(0, vicInfo.Name.LastIndexOf("."c)) _
.Substring(vicInfo.Name.IndexOf("_"c) + 1) & "_" & _
vicInfo.Name.Substring(0, vicInfo.Name.IndexOf("_"c))
Dim newFile As New XElement(vicName)
newDir.Add(newFile)
Next
root.Add(newDir)
Next
xDoc.Save(startPath & "\Vehicle_DB.xml")
Dim startPath As String = "C:\Vehicle_DB"
Dim dirInfo As New DirectoryInfo(startPath)
Dim xDoc As New XDocument(New XDeclaration("1.0", "utf-8", "yes"), New XElement("Vehicle_DB"))
Dim root As XElement = xDoc.Root
For Each dir As DirectoryInfo In dirInfo.GetDirectories()
Dim newDir As New XElement(dir.Name)
Dim vicDir() As DirectoryInfo = dir.GetDirectories()
For Each vicInfo As DirectoryInfo In dir.GetDirectories()
Dim vicName As String = vicInfo.Name.Substring(vicInfo.Name.IndexOf("_"c) + 1) & "_" & _
vicInfo.Name.Substring(0, vicInfo.Name.IndexOf("_"c))
Dim newVicDir As New XElement(vicName)
newDir.Add(newVicDir)
Next
root.Add(newDir)
Next
xDoc.Save(startPath & "\Vehicle_DB.xml")
Dim dirInfo As New DirectoryInfo(myFolderPath) ' myFolderPath instead of stringPath
Dim xDoc As New XDocument(New XDeclaration("1.0", "utf-8", "yes"), New XElement("Vehicle_DB"))
Dim root As XElement = xDoc.Root
For Each dir As DirectoryInfo In dirInfo.GetDirectories()
Dim newDir As New XElement(dir.Name)
' This line removed as you said
For Each vicInfo As DirectoryInfo In dir.GetDirectories()
Dim vicName As String = vicInfo.Name.Substring(vicInfo.Name.IndexOf("_"c) + 1) & "_" & _
vicInfo.Name.Substring(0, vicInfo.Name.IndexOf("_"c))
Dim newVicDir As New XElement(vicName)
newDir.Add(newVicDir)
Next
root.Add(newDir)
Next
xDoc.Save("Models.xml") ' INstead of saving it to Vehicles_DB I removed that ... I am assumming of course that this will save to application directory
YES?
SO maybe we could parse the directories and put into an xml file LIKE this
<?xml version="1.0" encoding="utf-8"?>
<Vehciles>
<VehMods>
<Make>Ford</Make>
<Model>F-150</Model>
<Years>1990 - 2010</Years>
<1990_Ford_F-150>Descripti
<1991_Ford_F-150>Descripti
<1992_Ford_F-150>Descripti
<1993_Ford_F-150>Descripti
AND SO ON ......
</Vehicles>
This makes sense as it will allow me to add other data and or needed info to specific Year of model
Just my thoughts