嘿伙计们我的vbs脚本有问题。我的脚本打开一个文本文件读取它并删除一些entrys。我的脚本中的Somwhere必须是错误,因为源文件的最后一行在目标文件中写入了大约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
答案 0 :(得分:1)
虽然这不会解决您的问题,但会降低您的If条件。你不需要4条件。只需使用And运算符,如下所示
If InStr(strLine, "Microsoft") = 0 And InStr(strLine, "TaskName") = 0 And InStr(strLine, "Restart System") = 0 AndA 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