ファイル検索VBScript
2010年1月8日
あるディレクトリにあるすべてのファイルの内容を、正規表現で検索するVBScript。
option explicit
dim fs,regex
set fs = WScript.CreateObject("Scripting.FileSystemObject")
set regex= new RegExp
regex.IgnoreCase=true
regex.Global=true
regex.Pattern=InputBox("regular expression pattern?")
if regex.Pattern="" then WScript.Quit()
WScript.Echo seek(".")
function seek(dir)
dim f,temp,ext
seek=""
Set f = fs.getFolder(dir)
For Each temp In f.SubFolders
if left(temp.Name,1)<>"." then seek = seek & seek(dir & "\" & temp.Name)
Next
For Each temp In f.Files
ext=right(temp.Name,4)
seek = seek & find(dir & "\" & temp.Name)
Next
end function
function find(file)
dim f,temp
find=""
set f = fs.OpenTextFile(file)
temp = f.ReadAll()
if regex.test(temp) then find= file & vbCrLf
end function