0

やあみんな私はtxtファイルを開いていくつかの行と各行を削除するために小さなvbsを書きました\。すべてが正しく機能しますが、ソースファイルの最後の行が宛先ファイルに複数回書き込まれます。その最後の行だけが他のすべての行に一度書き込まれます。では、私のコードの何が問題になっていますか?これが私がすることです:

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

文字列の後、ステートメントw.write strNewLine & VbCrLf内に移動する必要があります。IFstrNewLine =(Replace(strLine,"\","",1,1))

于 2013-03-25T10:38:54.743 に答える