[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
本帖最后由 czjt1234 于 2024-2-26 09:18 编辑
  1. rem 另存为 ANSI 编码 的 bat
  2. ' & cls & %windir%\SysWOW64\CScript.exe /nologo /e:vbscript "%~f0" & pause & exit
  3. Option Explicit
  4. Dim oWshShell, oFSO, oTextStream, oDOMDocument, oXMLDOMElement, oConnection, oRecordset, s, t
  5. Const PATH = "C:\Users\Administrator\Desktop\items"
  6. Const OUT  = "C:\Users\Administrator\Desktop\items\输出.txt"
  7. wsh.Echo Now()
  8. Set oWshShell    = CreateObject("WScript.Shell")
  9. Set oFSO         = CreateObject("Scripting.FileSystemObject")
  10. Set oTextStream  = oFSO.OpenTextFile(OUT, 2, True)
  11. Set oDOMDocument = CreateObject("Msxml2.DOMDocument")
  12. Set oConnection  = CreateObject("ADODB.Connection")
  13. Set oRecordset   = CreateObject("ADODB.Recordset")
  14. s = oFSO.BuildPath(PATH, "temp.mdb")
  15. If oFSO.FileExists(s) Then oFSO.DeleteFile s, True
  16. s = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & s
  17. CreateObject("ADOX.Catalog").Create s
  18. oConnection.Open s
  19. oConnection.Execute "CREATE TABLE list(id INT PRIMARY KEY, name VARCHAR)"
  20. t = "|"
  21. For Each s In oFSO.GetFolder(PATH).Files
  22.     If LCase(oFSO.GetExtensionName(s)) = "xml" Then Call k(s.Path)
  23. Next
  24. oRecordset.CursorLocation = 3    'adUseClient
  25. oRecordset.Open "SELECT * FROM list ORDER BY id ASC", oConnection
  26. s = ""
  27. For t = 0 To oRecordset.Fields.Count - 1
  28.     s = s & oRecordset(t).Name & vbTab
  29. Next
  30. s = Left(s, Len(s) - 1) & vbCrLf
  31. Do Until oRecordset.EOF = True
  32.     For t = 0 To oRecordset.Fields.Count - 1
  33.         s = s & oRecordset(t).Value & vbTab
  34.     Next
  35.     s = Left(s, Len(s) - 1) & vbCrLf
  36.     If Len(s) >= 2048 Then
  37.         oTextStream.Write s
  38.         s = ""
  39.     End If
  40.     oRecordset.MoveNext()
  41. Loop
  42. If s <> "" Then oTextStream.Write s
  43. oRecordset.Close()
  44. oConnection.Close()
  45. oTextStream.Close()
  46. s = oFSO.BuildPath(PATH, "temp.mdb")
  47. If oFSO.FileExists(s) Then oFSO.DeleteFile s, True
  48. wsh.Echo Now()
  49. wsh.Echo "ok"
  50. Sub k(ByVal s)
  51.     Dim i, j, m
  52.     oDOMDocument.Load s
  53.     Set oXMLDOMElement = oDOMDocument.documentElement
  54.     For Each i In oXMLDOMElement.SelectNodes("item[@id and @name]")
  55.         oConnection.Execute "INSERT INTO list(id, name) VALUES(" & i.getAttribute("id") & ", '" & i.getAttribute("name") & "')"
  56.         m = "UPDATE list SET "
  57.         For Each j In i.SelectNodes("set[@name and @val]")
  58.             If InStr(1, t, "|" & j.getAttribute("name") & "|", vbTextCompare) = 0 Then
  59.                 oConnection.Execute "ALTER TABLE list ADD COLUMN [" & j.getAttribute("name") & "] VARCHAR"
  60.                 t = t & j.getAttribute("name") & "|"
  61.             End If
  62.             If InStr(1, m, "[" & j.getAttribute("name") & "]", vbTextCompare) = 0 Then   '处理异常文件 id = 20994
  63.                 m = m & "[" & j.getAttribute("name") & "] = """ & j.getAttribute("val") & """, "
  64.             End If
  65.         Next
  66.         oConnection.Execute Left(m, Len(m) - 2) & " WHERE id = " & i.getAttribute("id")
  67.     Next
  68. End Sub
复制代码

QQ 20147578

TOP

返回列表