Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML File Structure

Status
Not open for further replies.

Rilez

Programmer
Jun 15, 2001
94
GB
Hi all
I have an application which needs an xml representation of the file structure on our server. This works perfectly but it currently takes a long time (approx 20 mins) to build. I was wondering if there was a quicker way of parsing through the directories rather than using the FileObject. Or is the performance problem coming from something else within the class? This runs from a web service to allow network credentials to be passed to it. I'm sure there must be a better way of doing this but I didn't really want to start messing with hundreds of threads. Any help would be appreciated

<WebMethod()> _
Public Sub CreateStruct()
Dim objoutput As New StreamWriter(&quot;c:\inetpub\newfilesystem2.xml&quot;)
objoutput.WriteLine(&quot;<?xml version=&quot;&quot;1.0&quot;&quot; ?>&quot;)
objoutput.Write(RetSubDirs(&quot;\\garincha\cvl&quot;))
objoutput.Close()
File.Delete(&quot;c:\inetpub\filesystem2.xml&quot;)
File.Copy(&quot;c:\inetpub\newfilesystem2.xml&quot;, &quot;c:\inetpub\filesystem2.xml&quot;)
End Sub

Function RetSubDirs(ByVal path As String) As String
Try
Dim strDirs() As String = Directory.GetDirectories(path)
Dim strReturn As String = &quot;<Directory>&quot; & vbCrLf & _
&quot;<Name><![CDATA[&quot; & path.Substring(path.LastIndexOf(&quot;\&quot;) + 1).TrimEnd(&quot; &quot;.ToCharArray) & &quot;]]></Name>&quot; & vbCrLf & _
&quot;<Path><![CDATA[&quot; & path & &quot;]]></Path>&quot; & vbCrLf & _
&quot;<Files>&quot; & Directory.GetFiles(path).Length & &quot;</Files>&quot; & vbCrLf
For Each strtemp As String In Directory.GetFiles(path)
strReturn &= &quot;<File>&quot; & strtemp & &quot;</File>&quot; & vbCrLf
Next
For Each strtemp As String In strDirs
strReturn &= RetSubDirs(strtemp)
Next
strReturn &= &quot;</Directory>&quot; & vbCrLf
Return strReturn
Catch e As Exception
Return User.Identity.Name.ToString & e.ToString
End Try
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top