Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
4.4 KiB

  1. '+----------------------------------------------------------------------
  2. '
  3. ' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  4. ' ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  5. ' THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  6. ' PARTICULAR PURPOSE.
  7. '
  8. ' Copyright 1999, Microsoft Corporation. All Rights Reserved.
  9. '
  10. ' SCRIPT: VBSQuery
  11. '
  12. ' PURPOSE: Illustrates how to execute an Indexing Service query
  13. ' using Microsoft Visual Basic Scripting Edition. The
  14. ' query uses the GroupBy property of the Query object
  15. ' to create a chaptered recordset of all files of a
  16. ' specified type in all directories that contain the
  17. ' specified file type.
  18. '
  19. ' PLATFORM: Windows 2000
  20. '
  21. '-----------------------------------------------------------------------
  22. Option Explicit
  23. Dim strGroupBy ' Name of GroupBy column.
  24. Dim intI, intJ ' Index variables.
  25. Dim objQ ' Query object.
  26. Dim strRecord ' Output record of query results.
  27. Dim objRS_Child ' Child RecordSet object.
  28. Dim objRS_Parent ' Parent RecordSet object.
  29. Dim intRS_Child_Count ' Number of current record of child RecordSet.
  30. Dim intRS_Parent_Count ' Number of current record of parent RecordSet.
  31. Dim objU ' Utility object.
  32. ' Create a Query object.
  33. Set objQ = WScript.CreateObject("IXSSO.Query")
  34. ' Set the properties of the Query object.
  35. objQ.Columns = "filename, directory, size, write"
  36. objQ.Query = "#filename *.asp"
  37. objQ.GroupBy = "directory[a]"
  38. objQ.Catalog = "system"
  39. objQ.OptimizeFor = "recall"
  40. objQ.AllowEnumeration = TRUE
  41. objQ.MaxRecords = 20000
  42. ' Create a Utility object.
  43. Set objU = WScript.CreateObject("IXSSO.Util")
  44. ' Add the physical path and all subdirectories.
  45. objU.AddScopeToQuery objQ, "\", "deep"
  46. ' Output the Query properties.
  47. WScript.Echo " Columns = " & objQ.Columns
  48. WScript.Echo " Query = " & objQ.Query
  49. WScript.Echo " GroupBy = " & objQ.GroupBy
  50. WScript.Echo " Catalog = " & objQ.Catalog
  51. WScript.Echo " CiScope = " & objQ.CiScope
  52. WScript.Echo " CiFlags = " & objQ.CiFlags
  53. WScript.Echo " OptimizeFor = " & objQ.OptimizeFor
  54. WScript.Echo " AllowEnumeration = " & CStr(objQ.AllowEnumeration)
  55. WScript.Echo " MaxRecords = " & objQ.MaxRecords
  56. ' Create a parent (grouped) RecordSet object for the Query.
  57. Set objRS_Parent = objQ.CreateRecordSet("nonsequential")
  58. ' Determine the name of the GroupBy column.
  59. strGroupBy = ""
  60. For intI = 0 to objRS_Parent.Fields.Count - 1
  61. If objRS_Parent(intI).Name <> "Chapter" Then
  62. If strGroupBy <> "" Then
  63. strGroupBy = strGroupBy & " " & objRS_Parent(intI).Name
  64. Else
  65. strGroupBy = objRS_Parent(intI).Name
  66. End If
  67. End If
  68. Next
  69. ' Read through the parent RecordSet object.
  70. intRS_Parent_Count = 0
  71. Do While Not objRS_Parent.EOF
  72. intRS_Parent_Count = intRS_Parent_Count + 1
  73. strRecord = Left(CStr(intRS_Parent_Count) & ". ", 4)
  74. ' Extract values for non-chaptered columns.
  75. For intI = 0 to objRS_Parent.Fields.Count - 1
  76. If objRS_Parent(intI).Name <> "Chapter" Then
  77. strRecord = strRecord & " " & objRS_Parent(intI).Value
  78. End If
  79. Next
  80. ' Output the values for non-chaptered columns.
  81. WScript.Echo strRecord
  82. ' Create a child RecordSet object for the chaptered columns.
  83. Set objRS_Child = objRS_Parent.Fields("Chapter").Value
  84. ' Read through the child (chaptered) RecordSet object.
  85. intRS_Child_Count = 0
  86. Do While Not objRS_Child.EOF
  87. intRS_Child_Count = intRS_Child_Count + 1
  88. strRecord = Left(CStr(intRS_Parent_Count) + "." + CStr(intRS_Child_Count) + ". ", 8)
  89. ' Extract values for chaptered columns.
  90. For intJ = 0 to objRS_Child.Fields.Count - 1
  91. If objRS_Child(intJ).Name <> "Chapter" Then
  92. If objRS_Child(intJ).Name <> strGroupBy Then
  93. strRecord = strRecord & " " & objRS_Child(intJ).Value
  94. End If
  95. End If
  96. Next
  97. ' Output the values for chaptered columns.
  98. WScript.Echo strRecord
  99. objRS_Child.MoveNext
  100. Loop
  101. ' Close the child RecordSet object.
  102. objRS_Child.Close
  103. Set objRS_Child = Nothing
  104. ' Move to the next record in the parent RecordSet object.
  105. objRS_Parent.MoveNext
  106. Loop
  107. ' Close the parent RecordSet object.
  108. objRS_Parent.Close
  109. Set objRS_Parent = Nothing
  110. WScript.Echo "Done!"