I have numerous xml files within a particular folder, all of which have the same format just different file names. I want to be able to read through each file in turn, check a particular value then move on to the next file etc. I'm not too hot on file system objects and would appreciate any help :)
Cheers
Start with
System.IO.Directory.GetFiles("...path...", "*.xml")
which returns you a string array containing the names of the files. You could then again load the XML file XmlDocument (or XPathDocument) and then query the data out of it (when you iterate through the array)
Docs:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemiodirectoryclasstopic.asp
Thanks joteke
I found the solution, I could have used a little less code but didn't put the file extention in the GetFiles method as you have done and had to check the extension later. But it does the trick :)
Dim dAs System.IO.DirectoryInfo =New System.IO.DirectoryInfo(xmlfolder)
Dim filesAsString() = System.IO.Directory.GetFiles(xmlfolder)
ForEach fileIn files
Dim fAs System.IO.FileInfo =New System.IO.FileInfo(file)
' check file extension is .xml
If f.Extension = ".xml"And Len(f.Name) = 12Then
strName = f.Name
num = Replace(strName, ".xml", "")
' create xml document
xmlDoc.Load(xmlfolder & "\" & strName)
xmltitle = xmlDoc.SelectSingleNode("/Form").Attributes("formTitle").Value
If xmlDoc.SelectSingleNode("/Form").Attributes("formTitle").Value = strTitleThen
filelist = filelist & "<a href="http://links.10026.com/?link="data_forms.aspx?num=" & num & """>" & num & "</a><br>"
lngCount = lngCount + 1
EndIf
EndIf
Next
Cheers
0 comments:
Post a Comment