Column property of Javascript FileSystemObject’s (FSO) textstream object returns the column number of the character being read by the textstream pointer while reading the text from the specified text file. Column property of textstream object works in both FileReading as well as FileWriting mode. Textstream cursor pointer resets the value of column property equal to 1 after new line feed at the end of each. It restarts the column number from 1 for each line of text file or stream.
Syntax for Javascript FSO textstream Column property
textStreamObj.Column;
textStreamObj can be initialized using FileSystemObject and its OpenTextFile method that will return the textstream retrieved from the specified text file.
Example of FSO textstream object Column 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.Write("Hello ");
// return the column number while writing into the text file.
document.write(txtFile.Column);
txtFile.WriteLine("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;
// reads the specified number of characters of the text file
text = txtFile.Read(52);
document.write("<pre>" + text + "</pre>");
document.write("<br />");
// returns the column number while reading the specified text file.
document.write(txtFile.Column);
txtFile.Close();
fso = null
// Output:
// 7
// Hello this is the first line of text file. Hello th
// 9
</script>
Continue to next tutorial: Javascript FSO textstream object Line property to learn how to get the current line number from a textstream.