Skip to content

Instantly share code, notes, and snippets.

@yukihane
Created April 13, 2012 13:50
Show Gist options
  • Save yukihane/2377021 to your computer and use it in GitHub Desktop.
Save yukihane/2377021 to your computer and use it in GitHub Desktop.
更新日が一定の期間中であるファイルから、特定の文字列が含まれているものを検索する。
'更新日が一定の期間中であるファイルから、特定の文字列が含まれているものを検索する。
'
'使用法:
'cscript search.vbs [検索対象ディレクトリ] [検索文字列] [更新日(最古)] [更新日(最新)]
Option Explicit
Dim STDOUT: Set STDOUT = WScript.StdOut
Dim FS: Set FS = CreateObject("Scripting.FileSystemObject")
Dim ARGS: Set ARGS = WScript.Arguments
Dim dir: Set dir = FS.GetFolder(ARGS(0))
Dim text: text = ARGS(1)
Dim dateMin: dateMin = CDate(ARGS(2))
Dim dateMax: dateMax = CDate(ARGS(3))
Dim file
For Each file In dir.Files
If dateMin <= file.DateLastModified And file.DateLastModified <= dateMax Then
Dim FP: Set FP = FS.OpenTextFile(file, 1)
Dim exists: exists = 0
Do Until FP.AtEndOfStream
Dim line: line = FP.ReadLine
If line <> vbNull Then
exists = InStrRev(line, text)
End If
If exists > 0 Then
Exit Do
End If
Loop
FP.Close
If exists > 0 Then
STDOUT.WriteLine FS.GetFileName(file)
End If
End If
Next
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment