我需要一个 VB 来从我的警报 log.txt 中找到(字符串)“错误”,如果警报 log.txt 有错误字符串,则必须将该特定日志移动到另一个指定位置。我对 VB 完全陌生,所以请帮帮我....
这是我使用的代码(谷歌搜索)..
Option Explicit
'*
Const ForWriting = 8
'*
Dim strGFI, objFSO1, objOutputFile
Dim strOTF, MyString, objFileSystem
Dim strWSE, strWritePath, objFile
Dim strInput, cFOL, StrDirectory
'*
cFOL = "C:\temp\"
strInput = Inputbox("Enter the text you would like to search for.")
MyString = "Workstation"
strWritePath = "c:\text" & MyString & ".txt"
strDirectory = "C:\temp\"
Set objFSO1 = CreateObject("Scripting.FileSystemObject")
If objFSO1.FileExists(strWritePath) Then
'Wscript.Echo "The file Exists"
Else
Set objFile = objFSO1.CreateTextFile(strDirectory & MyString & ".txt")
objFile = ""
End If
Set objFileSystem = CreateObject("Scripting.fileSystemObject")
Set objOutputFile = objFileSystem.OpenTextFile(strDirectory & MyString & ".txt", ForWriting)
If cFOL > "" Then
If strInput > "" Then
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objGFO
Set objGFO = objFSO.GetFolder(cFOL)
Dim objGFI
Set objGFI = objGFO.Files
For Each strGFI in objGFI
Dim objOTF
Set objOTF = objFSO.OpenTextFile(cFOL & "\" & strGFI.Name,1)
Do While Not objOTF.AtEndOfStream
strOTF = objOTF.ReadAll()
Loop
objOTF.Close()
Set objOTF = Nothing
'*
If InStr(LCase(strOTF), strInput) > 0 Then
strWSE = strWSE & strGFI.Name & " contains " & strInput & vbCrLf
Else
strWSE = strWSE & strGFI.Name & " Does not contain: " & strInput & vbCrLf
End If
Next
objOutputFile.WriteLine(strWSE)
objOutputFile.Close
'*
Set objGFI = Nothing
Set objGFO = Nothing
Set objFSO = Nothing
Set objFileSystem = Nothing
Set objFSO1 = Nothing
'*
WScript.Echo strWSE
Else
Wscript.Echo "You Clicked Cancel or no search string was defined."
End If
Else
Wscript.Echo "You Clicked Cancel or no search path was defined."
WScript.Quit
End If
在这里,它动态地要求识别 d 字符串。我希望它是静态的。