提供两种方法参考
1、一次性读出文件内所有内容,然后逐行处理
option explicit
dim fso,fread,str,strarry,linestr
set fso=createobject("scripting.filesystemobject")
set fread=opentextfile("test.txt",1)
str=fread.readall
fread.close
if str="" then
wscript.echo "file have not any content"
wscript.quit
end if
strarry=split(str,vbcrlf)
for each linestr in strarry
wscript.echo linestr '这里是用echo显示每一行的内容,你可以根据自己的需要做别的处理
next
set fso=nothing
2、每次读出一行内容处理
option explicit
dim fso,fread,strline
set fso=createobject("scripting.filesystemobject")
set fread=opentextfile("test.txt",1)
do until fread.atendofstream
strline=fread.readline
wscript.echo strline '这里也仅仅是显示一行内容而已
loop
fread.close
set fso=nothing