作者:许琼博762375 | 来源:互联网 | 2023-02-01 11:56
Ihavethefollowingtoreadafilelinebyline:我有以下内容逐行读取文件:wscript.echoBEGINfilePathWS
I have the following to read a file line by line:
我有以下内容逐行读取文件:
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"
The EOF()
function doesn't seem to work:
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'
I haven't programmed in VB before, but I'm trying to figure out loops so that I can modify a VB script I've been handed. I want to read a file line by line, and do something with each line. If I change the Do Until loop to Do Until StrData = EOF
, it works but throws an error when it gets to the end of the file:
我以前没有在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
I feel like there is probably an easy solution, but I haven't been able to find it. I've tried a few other solutions I've found online, but haven't got as close as the above.
我觉得可能有一个简单的解决方案,但我找不到它。我已经尝试了一些我在网上找到的其他解决方案,但还没有上述那么接近。
2 个解决方案