On Error Resume next Dim Version : Version = "1.0" ' Script version Dim Author : Author = "A. Westra" Dim objXML 'XML Document object Dim root 'Root element of the xml document Dim newNode ' XML Node object Dim cNode ' XML (child) Node object Dim cNodeText ' XML Text Node object
'***************************************************************** '** Make sure the script is started with cscript If InStr(wscript.FullName, "wscript.exe") > 0 Then MsgBox "Please run this script with cscript.exe." & Chr(13) & _ "For example : cscript " & WScript.ScriptName & " /?", _ vbExclamation, WScript.ScriptName WScript.Quit(1) End If
'***************************************************************** '** Get commandline parameters Set Args = Wscript.Arguments
If Args.Count = 0 Then strImageDir = InputBox("Please give the directory name " & _ "to process : ",wscript.scriptname, strPath) Else If InStr(Args(0),"/?") > 0 Or InStr(UCase(Args(0)),"/H") > 0 _ Or InStr(UCase(Args(0)),"/HELP") > 0 Then DisplayHelp Wscript.quit(0) Else strImageDir = Args(0) End if End if
Set objXML = CreateObject("Msxml2.DOMDocument.6.0") objXML.setProperty "SelectionLanguage", "XPath"
'***************************************************************** '** Determine if the file exists strXMLFile = strImageDir & "/album.xml" Set objFSO = CreateObject("Scripting.FileSystemObject") If objFSO.FileExists(strXMLFile) Then '***************************************************************** '** Read the XML File objXML.load(strXMLFile) Else '***************************************************************** '** Create the XML File objXML.loadXML("") End If '***************************************************************** '** Process directory Set objImgDir = objFSO.GetFolder(strImageDir) For each objFile in objImgDir.Files If IsJPG(objFile.Name) Then arrTemp = split(objFile.Name, ".") strNode = arrTemp(0)
'***************************************************************** '** Determine if the node exists If Not XmlNodeExists(strChildNode, objXML) Then '***************************************************************** '** Get the root element of the xml document Set root = objXML.documentElement '***************************************************************** '** Create the new node Set newNode = objXML.createNode(1, strNode, "") root.appendChild newNode Set cNode = objXML.createNode(1, "alt", "") Set cNodeText = objXML.createNode(3, "", "") cNodeText.Text = strNode cNode.appendChild cNodeText newNode.appendChild cNode Set cNode = objXML.createNode(1, "Title", "") Set cNodeText = objXML.createNode(3, "", "") cNodeText.Text = strNode cNode.appendChild cNodeText newNode.appendChild cNode End If End If Next '***************************************************************** '** Save the xml file objXML.save(strXMLFile)