此脚本通过 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
提前致谢。