此脚本通过Windows子文件夹查找XML文件。循环应加载XML文件并执行操作,然后传递给下一个XML文件等。
这条线没有像我希望的那样被解释:
If oXML.load(objFile.name) Then
WScript.Echo "XML file loaded"
编写此代码的正确方法是什么?
这是完整的脚本。
Set objFSO = CreateObject("Scripting.FileSystemObject")
objStartFolder = "C:\test_env"
set oXML = CreateObject("Msxml2.DOMDocument")
oXML.async = "false"
Set objFolder = objFSO.GetFolder(objStartFolder)
Wscript.Echo objFolder.Path
Set colFiles = objFolder.Files
For Each objFile in colFiles
Wscript.Echo objFile.Name
Next
Wscript.Echo
ShowSubfolders objFSO.GetFolder(objStartFolder)
Sub ShowSubFolders(Folder)
For Each Subfolder in Folder.SubFolders
Set objFolder = objFSO.GetFolder(Subfolder.Path)
Set colFiles = objFolder.Files
For Each objFile in colFiles
If UCase(objFSO.GetExtensionName(objFile.name)) = "XML" Then
Wscript.Echo Subfolder.Path
Wscript.Echo objFile.Name
' LOAD THE XML FILE
If oXML.load(objFile.name) Then
WScript.Echo "XML loaded"
Else WScript.Echo "XML not loaded"
End If
End If
Next
ShowSubFolders Subfolder
Next
End Sub
提前致谢。
答案 0 :(得分:0)
.load方法需要.xml文件的完整路径,因此请更改
If oXML.load(objFile.name) Then
到
If oXML.load(objFile.Path) Then
在失败的情况下查看.parseError.reason
可能是个好主意。