Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vbscript Can';在我的脚本中找不到错误_Vbscript - Fatal编程技术网

Vbscript Can';在我的脚本中找不到错误

Vbscript Can';在我的脚本中找不到错误,vbscript,Vbscript,嘿,伙计们,我的vbs脚本有问题。我的脚本打开一个文本文件,读取它并删除一些条目。Somwhere在我的脚本中肯定是一个错误,因为源文件的最后一行在目标文件中写入了大约30次。我没有在我的代码中找到错误,也许你们中的某个人看到了。是的,我知道我不应该发布大代码部分。以下是我的代码: separator = " " x = 0 strRawPath = "C:\xampp_neu\xampp\htdocs\tc_backup\stasknoheader.txt" strRawPathW = "C

嘿,伙计们,我的vbs脚本有问题。我的脚本打开一个文本文件,读取它并删除一些条目。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
separator=“”
x=0
strRawPath=“C:\xampp\u neu\xampp\htdocs\tc\u backup\stasknoheader.txt”
strRawPathW=“C:\xampp\u neu\xampp\htdocs\tc\u backup\stask.txt”
设置WSHShell=WScript.CreateObject(“WScript.Shell”)
设置fs=CreateObject(“Scripting.FileSystemObject”)
设置fsw=CreateObject(“Scripting.FileSystemObject”)
'2=用于写作
Set f=fs.OpenTextFile(strRawPath,1)
Set w=fsw.OpenTextFile(strRawPathW,2)
在f.AtEndOfStream为真时执行此操作
x=x+1
“安勒根阵列
ReDim保留myArray(x)
strLine=f.读线
“斯皮切恩在阵列中”
myArray(x)=strLine
'循环,以便不写入包含Microsoft或TaskName的行
如果InStr(strLine,“Microsoft”)=0,则
如果InStr(strLine,“TaskName”)=0,则
如果InStr(strLine,“重启系统”)=0,则
如果InStr(strLine,“调度器-HSM-mig-TC11TDrive”)=0,则
strNewLine=strNewLine&strLine&vbCrLf
'将空白替换为“AM,”
strNewLine=(替换(strLine,“,分离器,1,2))
'从TaskName中删除\
strNewLine=(替换(strNewLine,“\”,“,1,1))
'WScript.Echo strNewLine
如果结束
如果结束
如果结束
如果结束
w、 写入strNewLine和VbCrLf
'WScript.Echo strNewLine
环
f、 接近
w、 接近

虽然这不能解决您的问题,但会降低您的If条件。你不需要4如果条件。只需使用和运算符,如下所示

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  

那么你的意思是说这一行w.write strNewLine&VbCrLf被写入了30次?@AshReva只有当源文件的最后一行被写入dest文件时,它才会将其写入30次所有其他行都被写入dest,因为其余的行都在If条件内,而这是If条件外的唯一一行。所以该行将一直执行到循环运行。你从f.AtEndOfStream中得到任何计数或什么吗?你对
strNewLine
的处理变得不正常,因为在这条语句中
strNewLine=(Replace(strLine,“”,separator,1,2))
你只用分隔符替换上次读取的strLine(在最后一个循环中)中的空格。strNewLine上的所有其他突变都是无效的。我想你想要的是这样的:
strNewLine=(替换(strNewLine,”,分隔符,1,2))
(我用
strNewLine
替换了
newLine
)。总是,总是用。我不知道这是否能解决您的问题,但它在将来的某个时候会对您有所帮助。-1对于错误的答案:您的
建议包含的逻辑不正确,这应该是
@AutomatedChaos oops,我完全同意。“现在将更改它。@AutomatedChaos再次感谢。