嘿伙计们,我的 vbs 脚本有问题。我的脚本打开一个文本文件读取它并删除一些条目。我的脚本中的某个地方一定是一个错误,因为源文件的最后一行在目标文件中写入了大约 30 次。我在我的代码中没有发现错误,也许你们中的某个人看到了它。是的,我知道我不应该发布大型代码部分。这是我的代码:
separator = " "
x = 0
strRawPath = "C:\xampp_neu\xampp\htdocs\tc_backup\stasknoheader.txt"
strRawPathW = "C:\xampp_neu\xampp\htdocs\tc_backup\stask.txt"
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set fs = CreateObject("Scripting.FileSystemObject")
Set fsw = CreateObject("Scripting.FileSystemObject")
' 2 = ForWriting
Set f = fs.OpenTextFile(strRawPath,1)
Set w = fsw.OpenTextFile(strRawPathW,2)
Do While f.AtEndOfStream <> True
x = x+1
'Anlegen des Arrays
ReDim Preserve myArray(x)
strLine = f.Readline
'Speichern in Array
myArray(x) = strLine
'Loop so that lines that contains Microsoft or TaskName are not written
If InStr(strLine, "Microsoft") = 0 Then
If InStr(strLine, "TaskName") = 0 Then
If InStr(strLine, "Restart System") = 0 Then
If InStr(strLine, "Scheduler-HSM-mig-TC11TDrive") = 0 Then
strNewLine = strNewLine & strLine & vbCrLf
'Replace blank with " AM, "
strNewLine =(Replace(strLine," ",separator,1,2))
'Removes \ from TaskName
strNewLine =(Replace(strNewLine,"\","",1,1))
'WScript.Echo strNewLine
End If
End If
End If
End If
w.write strNewLine & VbCrLf
'WScript.Echo strNewLine
Loop
f.Close
w.Close