嘿伙计们我已经写了一些vbs来打开一个txt文件并删除一些行并在每行中\
。一切正常,但我的源文件的最后一行被多次写入目标文件。它只有最后一行所有其他行都写了一次。那我的代码有什么问题?这就是我的所作所为:
Option Explicit
Dim strLine
Dim strNewLine
Dim strRawPath
Dim strRawPathW
Dim WshShell
Dim f
Dim w
Dim fs
Dim fsw
Dim x
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
ReDim Preserve myArray(x)
strLine = f.Readline
myArray(x) = strLine
If InStr(strLine, "Microsoft") = 0 Then
If InStr(strLine, "TaskName") = 0 Then
If InStr(strLine, "Restart System") = 0 Then
IfInStr(strLine,"SchedulerHSMmigTC11TDrive") = 0 Then
strNewLine = strLine
strNewLine =(Replace(strLine,"\","",1,1))
End If
End If
End If
End If
w.write strNewLine & VbCrLf
Loop
f.Close
w.Close
答案 0 :(得分:1)
您需要在w.write strNewLine & VbCrLf
字符串后面IF
语句中移动strNewLine =(Replace(strLine,"\","",1,1))
。