The following example illustrates the use of the
AtEndOfLine property.
JScript
function ReadEntireFile(filespec)
{
var fso, a, s, ForReading;
ForReading = 1, s = "";
fso = new ActiveXObject("Scripting.FileSystemObject");
a = fso.OpenTextFile(filespec, ForReading, false);
while (!a.AtEndOfLine)
{
s += a.Read(1);
}
a.Close( );
return(s);
}
VBScript
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.AtEndOfLine <> True
retstring = retstring & theFile.Read(1)
Loop
theFile.Close
ReadEntireFile = retstring
End Function
PowerBASIC
SUB ReadEntireFile (BYVAL strFileSpec AS STRING)
LOCAL fso AS IFileSystem
LOCAL theFile AS ITextStream
LOCAL restring AS STRING
fso = NEWCOM ("Scripting.FileSystemObject")
theFile = fso.OpenTextFile(UCODE$(strFileSpec), %IOMode_ForReading, %VARIANT_FALSE)
DO
IF theFile.AtEndOfLine THEN EXIT DO
restring = retstring & theFile.Read(1)
LOOP
theFile.Close
FUNCTION = restring
END SUB