how to write in an xml file using vbscript??? I want to print the size and type of various files into an xml file and list it. how do I do it?
for example: folder E has 3 files. so wanna write a program such tht the program checks folder E, and lists the size and type of all files in it to an xml file
pls help
below is the program I have written to copy all the files of a folder to a text file.. but I want to copy to an xml
Option Explicit
Dim objFSO,objf,objfolder, objFile, strFileProperties, strFiles,OBJFLD,objfile2
dim objf1,objfile1,objtextfile,strfolderproperties,objsubfld
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objf= objFSO.Getfolder("C:\Test")
set OBJFLD=objf.subfolders
for each objfolder in OBJFLD
strFolderproperties = strFolderproperties & "Number of files: " & objFolder.Files.Count & VbCrLf
set objfile2=objfolder.files
for each objfile in objfile2
' Display generel file properties
strFileProperties = strFileProperties & "File name: " & objFile.Name & VbCrLf
strFileProperties = strFileProperties & "File path: " & objFile.Path & VbCrLf
strFileProperties = strFileProperties & "File size: " & objFile.Size & " bytes" & VbCrLf
strFileProperties = strFileProperties & "File type: " & objFile.Type & VbCrLf & vbcrlf
next
next
set objf1=objfso.getfolder("E:\logs3")
set objfile1=objfso.getfile( "E:\logs3\database.txt")
set objf1=nothing
set objfile1=nothing
set objtextfile=objfso.opentextfile("E:\logs3\database.txt",8,true)
objtextfile.writeline(strfileproperties)
objtextfile.close
set objf1=objfso.getfolder("E:\logs3")
set objfile1=objfso.getfile( "E:\logs3\database.txt")
set objf1=nothing
set objfile1=nothing
set objsubfld=objfso.opentextfile("E:\logs3\database.txt",8,true)
objsubfld.writeline(strfolderproperties)
objsubfld.close
As you mention
fciv
, you can use that program to determine the structure and content of your .xml file. Even when called with -r,fciv
will create a flat list of FILE_ENTRYs - do you need a hierarchical structure? For each file,fciv
adds path and signature elements - what exactly is the type info you mention? - should it encoded as element or attribute? - what else do you want to know about a file?Your specs should probably unequivocally fixed in a schema (.xsd) file.
Whether you decide to change/append to the .xml file created by
fciv
, or to create the file from scratch, you need a XML Document . Use that to .load the modifiedfciv
file resp. to create/append the standard 'headers', the reference to your .xsd, and a suitable root element.Changing means looping over all FILE_ENTRY nodes and appending child elements and/or attributes.
Creating a tree should be done with a function/sub that takes a parent node (folder element) and a folder. For each file in the folder a child node (file element, with suitable children/attributes) should be added. For Each subfolder, create a new folder element and send that (with the subfolder) recursively to the function/sub.
When all is done, .save the document.