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.

124 lines
4.3 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: JSQuery
  11. //
  12. // PURPOSE: Illustrates how to execute an Indexing Service query
  13. // using Microsoft JScript. The query uses the GroupBy
  14. // property of the Query object to create a chaptered
  15. // recordset of all files of a specified type in all
  16. // directories that contain the specified file type.
  17. //
  18. // PLATFORM: Windows 2000
  19. //
  20. //----------------------------------------------------------------------
  21. var strGroupBy; // Name of GroupBy column.
  22. var intI, intJ; // Index variables.
  23. var objQ; // Query object.
  24. var strRecord; // Output record of query results.
  25. var objRS_Child; // Child RecordSet object.
  26. var objRS_Parent; // Parent RecordSet object.
  27. var intRS_Child_Count; // Number of current record of child RecordSet.
  28. var intRS_Parent_Count; // Number of current record of parent RecordSet.
  29. var objU; // Utility object.
  30. // Create a Query object.
  31. objQ = new ActiveXObject("IXSSO.Query");
  32. // Set the properties of the Query object.
  33. objQ.Columns = "filename, directory, size, write";
  34. objQ.Query = "#filename *.asp";
  35. objQ.GroupBy = "directory[a]";
  36. objQ.Catalog = "system";
  37. objQ.OptimizeFor = "recall";
  38. objQ.AllowEnumeration = true;
  39. objQ.MaxRecords = 20000;
  40. // Create a Utility object.
  41. objU = new ActiveXObject("IXSSO.Util");
  42. // Add the physical path and all subdirectories.
  43. objU.AddScopeToQuery(objQ, "\\", "deep");
  44. // Output the Query properties.
  45. WScript.Echo(" Columns = " + objQ.Columns);
  46. WScript.Echo(" Query = " + objQ.Query);
  47. WScript.Echo(" GroupBy = " + objQ.GroupBy);
  48. WScript.Echo(" Catalog = " + objQ.Catalog);
  49. WScript.Echo(" CiScope = " + objQ.CiScope);
  50. WScript.Echo(" CiFlags = " + objQ.CiFlags);
  51. WScript.Echo(" OptimizeFor = " + objQ.OptimizeFor);
  52. WScript.Echo(" AllowEnumeration = " + objQ.AllowEnumeration);
  53. WScript.Echo(" MaxRecords = " + objQ.MaxRecords);
  54. // Create a parent (grouped) RecordSet object for the Query.
  55. objRS_Parent = objQ.CreateRecordSet("nonsequential");
  56. // Determine the name of the GroupBy column.
  57. strGroupBy = "";
  58. for (intI=0; intI<objRS_Parent.Fields.Count; intI++) {
  59. if (objRS_Parent(intI).Name != "Chapter") {
  60. if (strGroupBy != "")
  61. strGroupBy = strGroupBy + " " + objRS_Parent(intI).Name
  62. else
  63. strGroupBy = objRS_Parent(intI).Name;
  64. };
  65. };
  66. // Read through the parent RecordSet object.
  67. intRS_Parent_Count = 0;
  68. while (!objRS_Parent.EOF) {
  69. intRS_Parent_Count = intRS_Parent_Count + 1;
  70. strRecord = (intRS_Parent_Count + ". ").slice(0,4);
  71. // Extract values for non-chaptered columns.
  72. for (intI=0; intI<objRS_Parent.Fields.Count; intI++) {
  73. if (objRS_Parent(intI).Name != "Chapter")
  74. strRecord = strRecord + " " + objRS_Parent(intI).Value;
  75. };
  76. // Output the values for non-chaptered columns.
  77. WScript.Echo(strRecord);
  78. // Create a child RecordSet object for the chaptered columns.
  79. objRS_Child = objRS_Parent.Fields("Chapter").Value;
  80. // Read through the child (chaptered) RecordSet object.
  81. intRS_Child_Count = 0;
  82. while (!objRS_Child.EOF) {
  83. intRS_Child_Count = intRS_Child_Count + 1;
  84. strRecord = (intRS_Parent_Count + "." + intRS_Child_Count + ". ").slice(0,8);
  85. // Extract values for chaptered columns.
  86. for (intJ=0; intJ<objRS_Child.Fields.Count; intJ++) {
  87. if (objRS_Child(intJ).Name != "Chapter") {
  88. if (objRS_Child(intJ).Name != strGroupBy)
  89. strRecord = strRecord + " " + objRS_Child(intJ).Value;
  90. };
  91. };
  92. // Output the values for chaptered columns.
  93. WScript.Echo(strRecord);
  94. objRS_Child.MoveNext;
  95. };
  96. // Close the child RecordSet object.
  97. objRS_Child.Close;
  98. objRS_Child = null;
  99. // Move to the next record in the parent RecordSet object.
  100. objRS_Parent.MoveNext;
  101. };
  102. // Close the parent RecordSet object.
  103. objRS_Parent.Close;
  104. objRS_Parent = null;
  105. WScript.Echo("Done!");