Skip to content

Instantly share code, notes, and snippets.

@akirad
Last active May 31, 2023 03:10
Show Gist options
  • Save akirad/58237df345b22762555a572b0221eb78 to your computer and use it in GitHub Desktop.
Save akirad/58237df345b22762555a572b0221eb78 to your computer and use it in GitHub Desktop.
A vbs script that finds files that contains the string specified from the directory.
Option Explicit
Dim objArgs
Set objArgs = WScript.Arguments
If objArgs.Count < 1 Then
WScript.Echo("Specify a dir...")
WScript.Quit (1)
End If
Dim strPattern
strPattern = InputBox("Input a string you want to search.")
If Len(strPattern) = 0 Then
WScript.Echo("Specify a string to grep...")
WScript.Quit (1)
End If
Dim objFileSys, objDir
Set objFileSys = CreateObject("Scripting.FileSystemObject")
Set objDir = objFileSys.GetFolder(objArgs(0))
Dim objFile, strLine, objReadStream, strMsg, objRegExp
Set objRegExp = new RegExp
objRegExp.IgnoreCase = True
objRegExp.pattern = strPattern
For Each objFile In objDir.Files
Set objReadStream = objFileSys.OpenTextFile(objFile.Path, 1)
Do Until objReadStream.AtEndOfLine = True
strLine = objReadStream.ReadLine
If objRegExp.Test(strLine) Then
strMsg = strMsg & objFile.Path & " has " & strLine & vbCrLf
End If
Loop
Next
WScript.Echo(strMsg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment