Reading Text Files in WSH - More methods
(Page 3 of 4 )
Sometimes reading one character at a time just isn’t very useful or is inefficient. For those times, the TextStream Object provides a few more methods.
Methods:
object.ReadLine
object.ReadAll
object.Skip(Int)
object.SkipLine
Properties:
object.AtEndOfLine
object.Column
object.Line
The ReadLine method will read until it finds an end of line character (vbCr, vbLf, or vbCrLf) and return a string containing the characters excluding the line ending. The ReadAll method will read every character until it reaches an EOF marker before returning its findings as a string (including end of line indicators).
Exercise caution when using the ReadAll method with large files. You can run out of memory which will result in errors during execution.
The Skip method accepts an integer as its parameter and will skip reading the specified number of characters. The SkipLine method can be used to skip an entire line or continue until the next end of line indicator.
Several properties are also available that can help you determine where the file pointer is in a file. AtEndOfLine works in much the same way as AtEndOfStream except that it returns a Boolean value indicating whether the file pointer is at an end of line indicator.
The Column property returns an integer indicating the position of the file pointer in the current line. The first character of the line is position 1. The Line property returns the current line number. The first line in the file is line 1.
Next: Advanced concepts >>
More Windows Scripting Articles
More By Nilpo/Developer Shed Staff Writer