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("c:\inetpub\newfilesystem2.xml"
objoutput.WriteLine("<?xml version=""1.0"" ?>"
objoutput.Write(RetSubDirs("\\garincha\cvl"
)
objoutput.Close()
File.Delete("c:\inetpub\filesystem2.xml"
File.Copy("c:\inetpub\newfilesystem2.xml", "c:\inetpub\filesystem2.xml"
End Sub
Function RetSubDirs(ByVal path As String) As String
Try
Dim strDirs() As String = Directory.GetDirectories(path)
Dim strReturn As String = "<Directory>" & vbCrLf & _
"<Name><![CDATA[" & path.Substring(path.LastIndexOf("\"
+ 1).TrimEnd(" ".ToCharArray) & "]]></Name>" & vbCrLf & _
"<Path><![CDATA[" & path & "]]></Path>" & vbCrLf & _
"<Files>" & Directory.GetFiles(path).Length & "</Files>" & vbCrLf
For Each strtemp As String In Directory.GetFiles(path)
strReturn &= "<File>" & strtemp & "</File>" & vbCrLf
Next
For Each strtemp As String In strDirs
strReturn &= RetSubDirs(strtemp)
Next
strReturn &= "</Directory>" & vbCrLf
Return strReturn
Catch e As Exception
Return User.Identity.Name.ToString & e.ToString
End Try
End Function
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("c:\inetpub\newfilesystem2.xml"
objoutput.WriteLine("<?xml version=""1.0"" ?>"
objoutput.Write(RetSubDirs("\\garincha\cvl"
objoutput.Close()
File.Delete("c:\inetpub\filesystem2.xml"
File.Copy("c:\inetpub\newfilesystem2.xml", "c:\inetpub\filesystem2.xml"
End Sub
Function RetSubDirs(ByVal path As String) As String
Try
Dim strDirs() As String = Directory.GetDirectories(path)
Dim strReturn As String = "<Directory>" & vbCrLf & _
"<Name><![CDATA[" & path.Substring(path.LastIndexOf("\"
"<Path><![CDATA[" & path & "]]></Path>" & vbCrLf & _
"<Files>" & Directory.GetFiles(path).Length & "</Files>" & vbCrLf
For Each strtemp As String In Directory.GetFiles(path)
strReturn &= "<File>" & strtemp & "</File>" & vbCrLf
Next
For Each strtemp As String In strDirs
strReturn &= RetSubDirs(strtemp)
Next
strReturn &= "</Directory>" & vbCrLf
Return strReturn
Catch e As Exception
Return User.Identity.Name.ToString & e.ToString
End Try
End Function