【发布时间】:2016-02-24 08:21:58
【问题描述】:
我正在使用一些 vbscript 在目录中搜索字符串。现在我需要我的脚本在每个文件中搜索多个字符串实例并返回行号或其他一些可识别信息。我目前的 vbscript 是:-
Sub ProcessFolder(FolderPath)
On Error Resume Next
Set fldr = fso.GetFolder(FolderPath)
Set Fls = fldr.files
For Each thing in Fls
Set contents = thing.OpenAsTextStream
If err.number = 0 then
Test = Instr(contents.readall, searchterm)
If Isnull(test) = false then If Test > 0 then ObjOutFile.WriteLine thing.path
demo.innerHtml = demo.innerHtml & thing.path & "<br>"
Else
err.clear
End If
Next
Set fldrs = fldr.subfolders
For Each thing in fldrs
ProcessFolder thing.path
Next
End Sub
我需要遍历每个文件的行以获取包含字符串的行号。
【问题讨论】:
-
完整的hta文件可以在这里找到gist.github.com/SanjeetSk/268b293682c14fa5ac7a
-
Do While Not thing.AtEndOfStream strLine = objFile.readline 也许我可以用这个
-
受此代码启发 ==> stackoverflow.com/questions/22854627/…
-
test变量具有在文件中找到的第一个字符串的字符偏移量。 -
上面的
readall方法也可以改成readline。