ファイル・ポインタが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")