我正在尝试提高vb脚本的性能。我需要vbs以编程方式将xml文件转换并导入MS Access数据库,并且运行速度很快。在一个完整的xml文件(2000)的目录上运行xsl转换后,我将导入到Access。这需要大约一秒钟。
我想在导入之前添加一个Python(脚本或可执行文件)步骤来处理XML。这适用于独立的XML文件。
我的问题是如何在多个文件上运行Python代码,而无需打开和关闭命令窗口占用太多时间。运行以下示例代码看起来没问题,但需要大约30秒才能完成400次。有没有办法在一个命令行实例中顺序运行Python?我不想连接2000多个电话。我可以在一个窗口中完成吗?
'usage: wscript multi-dir.vbs c:\my\xml\xml
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(WScript.arguments.item(0))
Set fc = f.Files
Dim filecount
filecount = 0
filecount = CInt(filecount)
Set oShell = WScript.CreateObject("WScript.Shell")
oShell.CurrentDirectory = "C:\my\xml"
'Maybe call the oShell.run command here?
For Each f1 In fc
'Load an xml file, transform it, save it
'xml.load f1.Path
'xmlTransformedResult = xml.transformNode(xsl)
'and each command to run here? <--------- ?????
'the type command is just an example command here, it would be the python call.
oShell.Run "%comspec% /k type TransformOutput.xml", 0, False
'Now do the Access Import here
'objAccess.ImportXML xmlTransformOutputFile, 2
filecount = filecount + 1
Next
WScript.Echo "Processed " & filecount & " files."