Javascript FileSystemObject (FSO) textstream object provides a property AtEndOfStream that returns the status of file reading pointer whether it is at the end of any file retrived in the form textstream object. FSO OpenTextFile method supports the AtEndOfStream property when file is opened with FileReading mode. AtEndOfStream property returns the Boolean result i.e. true or false based on the position of the textstream file reading pointer. If file pointer is at the end of the text stream then it returns true otherwise it returns false.

Syntax for Javascript FSO textstream AtEndOfStream property

textStreamObj.AtEndOfStream;

textStreamObj can be initialized using FileSystemObject and its OpenTextFile method that will return the textstream retrieved from the specified text file.

Example of Javascript FSO textstream object AtEndOfStream property

<script type="text/javascript">
    // initialize ActiveXObject and create an object of Scripting.FileSystemObject.
    var fso = new ActiveXObject("Scripting.FileSystemObject");

    // Open the text file at the specified location with write mode
    var txtFile = fso.OpenTextFile("C:\\Temp\\myFolder\\file.txt", 2, false, 0);
    txtFile.WriteLine("Hello this is the first line of text file.");
    txtFile.WriteLine("Hello this is the second line of text file.");
    txtFile.WriteLine("Hello this is the third line of text file.");

    txtFile.Close();

    // Open the text file at the specified location with read mode
    txtFile = fso.OpenTextFile("C:\\Temp\\myFolder\\file.txt", 1, false, 0);

    var text;

    // read 1st character of first line of the text file
    text = txtFile.Read(1);

    // returns the status of AtEndOfStream property
    document.write("<b>AtEndOfStream :</b> " + txtFile.AtEndOfStream);
    document.write("<br />");

    // while loop used to read all lines with condition AtEndOfStream!=true
    // this loop will work until AtEndOfStream=false and will exit the loop when AtEndOfStream=true
    while (txtFile.AtEndOfStream != true) {
        text += txtFile.ReadLine();
        text += "<br />";
    }

    document.write("<b>Strings returned :</b> " + text);
    document.write("<br />");

    document.write("<b>AtEndOfStream :</b> " + txtFile.AtEndOfStream);
    document.write("<br />");

    txtFile.Close();
    fso = null;

    // Output: AtEndOfStream : false 
        
    // String returned : 
    // Hello this is the first line of text file. 
    // Hello this is the second line of text file. 
    // Hello this is the third line of text file. 

    // AtEndOfStream : true
</script>

Continue to next tutorial: Javascript FSO textstream object Column property to learn how to get the column number of the current character in a textstream.

Recent JavaScript Tutorials

Javascript FSO ShortPath property

Javascript FileSystemObject (FSO) provides a ShortPath property that can be accessed using the folder object or file object returned by the GetFolder or GetFile method.

Javascript FSO Path Property

Javascript FileSystemObject (FSO) provides the Path property that can be accessed through the file object or folder object returned by the GetFile or GelFolder method

Javascript FSO Type property

Javascript FileSystemObject (FSO) provides a Type property that can be accessed through file object or folder object returned by the GetFile or GetFolder method

Javascript FSO ShortName property

Javascript FileSystemObject (FSO) provides a ShortName property that can be accessed using the folder object or file object returned by the GetFolder or GetFile method.

Javascript FSO Name Property

Javascript FileSystemObject (FSO) provides a Name property that can be accessed using file object or folder object.