本帖最后由 apang 于 2015-3-7 16:13 编辑
要停止,在任务管理器中结束 WScript.exe 进程
或者,时间累加后的值大于当前时间即自动退出- ''On Error Resume Next
- Dim strDir, arrKey, strDt
- strDir = "D:\Test"
- arrKey = Array(":L ABC", ":OP 1.5", "XXX")
- strDt = "2015/3/1 8:05:00"
-
- Do while DateDiff("s", strDt, Now()) > 0
- call Main()
- strDt = DateAdd("n", "10", strDt) ''加 10 分钟
- WScript.Sleep 5000
- Loop
-
- Sub Main()
- Dim fso, f, txt, objFile, s
- s = ""
- Set fso = CreateObject("Scripting.FileSystemObject")
- For Each f in fso.GetFolder(strDir).Files
- If LCase(Right(f, 4)) = ".txt" Then
- If DateDiff("s", strDt, f.DateLastModified) > 0 Then
- Set objFile = fso.OpentextFile(f, 1)
- txt = objFile.ReadAll
- If TestKeyWord(txt) Then s = s & f.Name & vbCrLf
- objFile.Close
- End If
- End If
- Next
- fso.OpenTextFile("a.txt", 2, true).Write s
- CreateObject("WScript.Shell").Run "cmd /c ""ch.bat""",,true ''调用bat
- Set fso = Nothing
- End Sub
-
- Function TestKeyWord(ByVal txt)
- Dim i
- TestKeyWord = True
- txt = vbCrLf & txt & vbCrLf
- For i = 0 to UBound(arrKey)
- If InStr(txt, vbCrLf & arrKey(i) & vbCrLf) = 0 Then
- TestKeyWord = False : Exit For
- End If
- Next
- End Function
复制代码
|