我有以下内容逐行读取文件:
wscript.echo "BEGIN"
filePath = WScript.Arguments(0)
filePath = "C:\Temp\vblist.txt"
Set ObjFso = CreateObject("Scripting.FileSystemObject")
Set ObjFile = ObjFso.OpenTextFile(filePath)
StrData = ObjFile.ReadLine
wscript.echo "END OF FIRST PART"
Do Until StrData = EOF(ObjFile.ReadLine)
wscript.echo StrData
StrData = ObjFile.ReadLine
Loop
wscript.echo "END"
该EOF()
功能似乎不起作用:
C:\Users\EGr\Documents\Scripts\VB>cscript testloop.vbs ArgVal
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.
BEGIN
END OF FIRST PART
C:\Users\EGr\Documents\Scripts\VB\testloop.vbs(11, 1) Microsoft VBScript runti
me error: Type mismatch: 'EOF'
我以前没有在 VB 中编程,但我正在尝试找出循环,以便我可以修改我收到的 VB 脚本。我想逐行读取文件,并对每一行做一些事情。如果我将 Do Until 循环更改为Do Until StrData = EOF
,它可以工作,但在到达文件末尾时会引发错误:
C:\Users\EGr\Documents\Scripts\VB>cscript testloop.vbs ThisRANDOMValue
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.
BEGIN
1
END OF FIRST PART
host1
host2
host3
C:\Users\EGr\Documents\Scripts\VB\testloop.vbs(13, 2) Microsoft VBScript runti
me error: Input past end of file
我觉得可能有一个简单的解决方案,但我一直无法找到它。我尝试了一些我在网上找到的其他解决方案,但没有像上面那样接近。