a.txt内容如下 想从a.txt中选出所有含有b.txt内容的行,并输出到c.txt中,代码如下,出现的问题是:输出的c.txt中只有(1,2,3),也就是当遇到b.txt中的"56"时,
1
2 因在a.txt中没有找到相应行,脚本就自动退出了,想请问一下是什么原因,应该如何解决?(不用findstr是因为就想学习一下VBS)请指教,谢谢
3
4
5
6
7
b.txt内容如下
1
2
3
56
4
5
a.vbs内容如下
Set fso = CreateObject("Scripting.FileSystemObject")
Set f1 = fso.GetFile("b.txt")
Set f2 = fso.GetFile("a.txt")
Set ts1 = f1.OpenAsTextStream(1,-2)
Set ts2 = f2.OpenAsTextStream(1,-2)
Set f3 = fso.OpenTextFile("c.txt",2,True)
Do Until ts1.AtEndOfStream
RL1 = ts1.ReadLine
Do While ts2.AtEndOfStream <> True
RL2 = ts2.ReadLine
If InStr(RL2,RL1) Then
f3.WriteLine RL2
Exit Do
End If
Loop
Set ts2 = f2.OpenAsTextStream(1,-2)
Loop
[ Last edited by waynebeat on 2010-8-28 at 22:59 ]
1
2 因在a.txt中没有找到相应行,脚本就自动退出了,想请问一下是什么原因,应该如何解决?(不用findstr是因为就想学习一下VBS)请指教,谢谢
3
4
5
6
7
b.txt内容如下
1
2
3
56
4
5
a.vbs内容如下
Set fso = CreateObject("Scripting.FileSystemObject")
Set f1 = fso.GetFile("b.txt")
Set f2 = fso.GetFile("a.txt")
Set ts1 = f1.OpenAsTextStream(1,-2)
Set ts2 = f2.OpenAsTextStream(1,-2)
Set f3 = fso.OpenTextFile("c.txt",2,True)
Do Until ts1.AtEndOfStream
RL1 = ts1.ReadLine
Do While ts2.AtEndOfStream <> True
RL2 = ts2.ReadLine
If InStr(RL2,RL1) Then
f3.WriteLine RL2
Exit Do
End If
Loop
Set ts2 = f2.OpenAsTextStream(1,-2)
Loop
[ Last edited by waynebeat on 2010-8-28 at 22:59 ]
