如果檔案指標位於 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")