0

やあみんな私は私の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
4

1 に答える 1

1

これは問題を解決しませんが、If 条件を減らします。4 if 条件は必要ありません。以下のように 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  
于 2013-03-22T09:58:40.247 に答える