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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Building XML of filestructure 1

Status
Not open for further replies.

peterneve

Programmer
Jan 24, 2002
50
GB
I need to look at the complete file structure of a machine on a regular basis, so we are building an XML file of the complete file structure. The resulting XML file looks like

Code:
<folder name="windows">
  <file name="explorer.exe">
  <file name="iexplorer.exe">
  <folder name="system32">
    <file name="explorer.dll">
    <file name="iexplorer.dll">
  </folder>
</folder>
etc...

Currently we have a script which run tree in dos and then parses through the output file from tree. Surely there's a simpler way?

Any ideas?
 
I don't know about a simpler way, but a self calling recursive function in VBScript to parse the directories would be more elegant IMO.

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
Do a keyword search in this forum for fso recursive

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Just for the record, this is the script that I have found

Code:
Dim objFSO
Dim ofolder
Dim objStream


Set objFSO = CreateObject("scripting.filesystemobject")

'create the output file
Set objStream = objFSO.createtextfile("search.xml", True)
MsgBox "Searching folders"
CheckFolder (objFSO.getfolder("C:\")), objStream
MsgBox "File Search Completed." + vbCr + "Please check search.xml for details."

Sub CheckFolder(objCurrentFolder, objLogFile)

    Dim strTemp
    Dim strSearch
    Dim strOutput
    Dim objNewFolder
    Dim objFile
    Dim objStream

       strOutput = "<folder name='" + CStr(objCurrentFolder.Name) + "'>"
       objLogFile.writeline strOutput
   
       For Each objFile In objCurrentFolder.Files
            strOutput = "<file name='" + CStr(objFile.Name) + "' />"
            objLogFile.writeline strOutput
       Next

       'Recurse through all of the folders
       For Each objNewFolder In objCurrentFolder.subFolders
               CheckFolder objNewFolder, objLogFile
       Next

       strOutput = "</folder>"
       objLogFile.writeline strOutput
       
End Sub

Works great using fso recursive trick.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top