我正在通过查询将 XML 文件加载到 SQL Server 中,问题是有一个 10x10 表存在多个命名空间问题。我想我可以用一些 vbscript 来解决这个问题,到目前为止,这是我拥有的代码;
Dim FSO, FLD, FIL
Dim strFolder
strFolder = "C:\Documents and Settings\Administrator\Desktop\Tests"
Set FSO = CreateObject ("Scripting.FileSystemObject")
Set FLD = FSO.GetFolder (strFolder)
For Each FIL in FLD.Files
Set objFS = CreateObject("Scripting.FileSystemObject")
i=1
Set objFile = objFS.OpenTextFile(FIL)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
If i=1 and InStr(strLine,"Data")> 0 Then
strLine = Replace(strLine,"Data","Data1")
i=i+1
ElseIf i=2 and InStr(strLine,"Data")> 0 Then
strLine = Replace(strLine,"Data","Data1")
i=i+1
ElseIf i=3 and InStr(strLine,"Data")> 0 Then
strLine = Replace(strLine,"Data","Data2")
i=i+1
ElseIf i=4 and InStr(strLine,"Data")> 0 Then
strLine = Replace(strLine,"Data","Data2")
i=i+1
ElseIf i=5 and InStr(strLine,"Data")> 0 Then
strLine = Replace(strLine,"Data","Data3")
i=i+1
ElseIf i=6 and InStr(strLine,"Data")> 0 Then
strLine = Replace(strLine,"Data","Data3")
i=i+1
ElseIf i=7 and InStr(strLine,"Data")> 0 Then
strLine = Replace(strLine,"Data","Data4")
i=i+1
ElseIf i=8 and InStr(strLine,"Data")> 0 Then
strLine = Replace(strLine,"Data","Data4")
i=i+1
ElseIf i=9 and InStr(strLine,"Data")> 0 Then
strLine = Replace(strLine,"Data","Data5")
i=i+1
ElseIf i=10 and InStr(strLine,"Data")> 0 Then
strLine = Replace(strLine,"Data","Data5")
i=i+1
ElseIf i=11 and InStr(strLine,"Data")> 0 Then
strLine = Replace(strLine,"Data","Data6")
End If
WScript.Echo strLine
Loop
next
When I run this via command prompt:
cd c:\
cscript /nologo Script.vbs >newfile
ren newfile example.xml
保存的文件 example.xml 是完美的 - 带有 if then 语句的脚本的中心部分正确地完成了它的工作。但是,只有在“测试”文件夹中我只存储一个文件时,它才能正常工作。如果我存储多个文件,并以相同的方式使用 cmd ,它将背靠背保存所有这些文件。大约有 3,000 个文件需要这样做,我想做的是在每个 .xml 文件上运行脚本,然后将其保存为具有相同名称的 new.xml(或者覆盖到新位置)文件夹。我将如何使用相同的名称但通过编辑保存它们?
谢谢你的帮助