AtEndOfStream Method
Returns true if the file pointer is at the end of a TextStream file; false if it is not. Read-only.
Syntax
object.AtEndOfStream
Arguments
Object: Required. Always the name of a TextStream
object.
Remarks
The AtEndOfStream
property applies only to
TextStream
files that are open for reading, otherwise, an error
occurs.
The following code illustrates the use of the AtEndOfStream
property:
Example 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")
Example 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")