如果文件指针位于 TextStream 文件的末尾,则返回 true;如果不在末尾,则返回 false。只读。
语法
object.AtEndOfStream
参数
Object:必需。始终为 TextStream 对象的名称。
注释
AtEndOfStream 属性仅适用于打开的供进行读取的 TextStream 文件,否则会出现错误。
以下代码说明了 AtEndOfStream 属性的用法:
示例 1:
Function ReadEntireFile(filespec)
Const ForReading = 1
Dim fso, theFile, retstring
Set fso = CreateObject("Scripting.FileSystemObject")
Set theFile = fso.OpenTextFile(filespec, ForReading, False)
Do While theFile.AtEndOfStream <> True
retstring = retstring & theFile.ReadLine
Loop
theFile.Close
ReadEntireFile = retstring
End Function
' Usage
Dim fileContent
fileContent = ReadEntireFile("C:\Path\To\Your\File.txt")
示例 2:
Function ReadUntilString(filespec, searchString)
Const ForReading = 1
Dim fso, theFile, line, foundString
Set fso = CreateObject("Scripting.FileSystemObject")
Set theFile = fso.OpenTextFile(filespec, ForReading, False)
foundString = False
Do While theFile.AtEndOfStream <> True And foundString = False
line = theFile.ReadLine
If InStr(line, searchString) > 0 Then
foundString = True
End If
Loop
theFile.Close
If foundString Then
ReadUntilString = "String found: " & line
Else
ReadUntilString = "String not found."
End If
End Function
' Usage
Dim result
result = ReadUntilString("C:\Path\To\Your\File.txt", "searchString")