1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

コマンドでインデックス検索(複数キーワードに対応)

Last updated at Posted at 2019-08-13

コマンドでインデックス検索 - Qiita
の続きです。前回は引数に指定したキーワードを検索する仕組みでしたが、「検索したいキーワードが沢山あるから、一括検索したい!」という要望に対応してみました。

スクリプト

vbsで実装しました。

test.vbs
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=Search.CollatorDSO;Extended Properties='Application=Windows';"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(Wscript.Arguments(0))
Do While objFile.AtEndOfStream <> True
    keyword = objFile.ReadLine
    Wscript.Echo "【" & keyword & "の検索結果は…】"
    Set objRecordset = CreateObject("ADODB.Recordset")
    objRecordset.Open "SELECT System.ItemPathDisplay FROM SYSTEMINDEX WHERE Contains('" & keyword & "')", objConnection
    Do Until objRecordset.EOF
        Wscript.Echo objRecordset.Fields.Item("System.ItemPathDisplay")
        objRecordset.MoveNext
    Loop
    Wscript.Echo ""
Loop

使い方

キーワード一覧を作成します。

list.txt
あいうえお
かきくけこ
さしすせそ

上記vbsファイルをcmdで実行します。引数にキーワード一覧を指定します。

cmd
C:\Users\xxxx\Desktop>cscript test.vbs list.txt
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.

【あいうえおの検索結果は…】
C:\ユーザー\xxxx\デスクトップ\あいうえお.txt

【かきくけこの検索結果は…】
C:\ユーザー\xxxx\デスクトップ\かきくけこ.txt

【さしすせその検索結果は…】
C:\ユーザー\xxxx\デスクトップ\さしすせそ.txt

C:\Users\xxxx\Desktop>

ちょっと便利に使えるかもしれません♪

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?