本帖最后由 czjt1234 于 2024-2-26 09:18 编辑
- rem 另存为 ANSI 编码 的 bat
- ' & cls & %windir%\SysWOW64\CScript.exe /nologo /e:vbscript "%~f0" & pause & exit
-
- Option Explicit
- Dim oWshShell, oFSO, oTextStream, oDOMDocument, oXMLDOMElement, oConnection, oRecordset, s, t
-
- Const PATH = "C:\Users\Administrator\Desktop\items"
- Const OUT = "C:\Users\Administrator\Desktop\items\输出.txt"
-
- wsh.Echo Now()
- Set oWshShell = CreateObject("WScript.Shell")
- Set oFSO = CreateObject("Scripting.FileSystemObject")
- Set oTextStream = oFSO.OpenTextFile(OUT, 2, True)
- Set oDOMDocument = CreateObject("Msxml2.DOMDocument")
- Set oConnection = CreateObject("ADODB.Connection")
- Set oRecordset = CreateObject("ADODB.Recordset")
-
- s = oFSO.BuildPath(PATH, "temp.mdb")
- If oFSO.FileExists(s) Then oFSO.DeleteFile s, True
- s = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & s
- CreateObject("ADOX.Catalog").Create s
- oConnection.Open s
- oConnection.Execute "CREATE TABLE list(id INT PRIMARY KEY, name VARCHAR)"
-
- t = "|"
- For Each s In oFSO.GetFolder(PATH).Files
- If LCase(oFSO.GetExtensionName(s)) = "xml" Then Call k(s.Path)
- Next
- oRecordset.CursorLocation = 3 'adUseClient
- oRecordset.Open "SELECT * FROM list ORDER BY id ASC", oConnection
- s = ""
- For t = 0 To oRecordset.Fields.Count - 1
- s = s & oRecordset(t).Name & vbTab
- Next
- s = Left(s, Len(s) - 1) & vbCrLf
- Do Until oRecordset.EOF = True
- For t = 0 To oRecordset.Fields.Count - 1
- s = s & oRecordset(t).Value & vbTab
- Next
- s = Left(s, Len(s) - 1) & vbCrLf
- If Len(s) >= 2048 Then
- oTextStream.Write s
- s = ""
- End If
- oRecordset.MoveNext()
- Loop
- If s <> "" Then oTextStream.Write s
- oRecordset.Close()
- oConnection.Close()
- oTextStream.Close()
-
- s = oFSO.BuildPath(PATH, "temp.mdb")
- If oFSO.FileExists(s) Then oFSO.DeleteFile s, True
- wsh.Echo Now()
- wsh.Echo "ok"
-
- Sub k(ByVal s)
- Dim i, j, m
- oDOMDocument.Load s
- Set oXMLDOMElement = oDOMDocument.documentElement
- For Each i In oXMLDOMElement.SelectNodes("item[@id and @name]")
- oConnection.Execute "INSERT INTO list(id, name) VALUES(" & i.getAttribute("id") & ", '" & i.getAttribute("name") & "')"
- m = "UPDATE list SET "
- For Each j In i.SelectNodes("set[@name and @val]")
- If InStr(1, t, "|" & j.getAttribute("name") & "|", vbTextCompare) = 0 Then
- oConnection.Execute "ALTER TABLE list ADD COLUMN [" & j.getAttribute("name") & "] VARCHAR"
- t = t & j.getAttribute("name") & "|"
- End If
- If InStr(1, m, "[" & j.getAttribute("name") & "]", vbTextCompare) = 0 Then '处理异常文件 id = 20994
- m = m & "[" & j.getAttribute("name") & "] = """ & j.getAttribute("val") & """, "
- End If
- Next
- oConnection.Execute Left(m, Len(m) - 2) & " WHERE id = " & i.getAttribute("id")
- Next
- End Sub
复制代码
|