0

嘿伙计们,我写了一个小 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
4

1 回答 1

1

You need just move w.write strNewLine & VbCrLf inside IF statetment, after strNewLine =(Replace(strLine,"\","",1,1)) string.

于 2013-03-25T10:38:54.743 回答