2013-03-25 102 views
0

嘿家伙我写了一些vbs打开一个txt文件,并删除了一些行和\在每一行。一切正常,但我的源文件的最后一行是多次写入目标文件。它只有最后一行所有其他行被写入一次。那么我的代码有什么问题?这是我做的:从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

第一之前'如果InStr函数(..''写= strNewLine strLine' – VMV 2013-03-25 08:41:40

+0

@VMV这并不能帮助它破坏更詹它有助于 – Alesfatalis 2013-03-25 09:23:00

+0

然后请解释这行应该被移除并处理? – VMV 2013-03-25 09:43:38

回答

1

你只需要移动w.write strNewLine & VbCrLfIF statetment,后strNewLine =(Replace(strLine,"\","",1,1))字符串。