Writing Text Files in WSH - Advanced Writing Methods
(Page 3 of 4 )
You can pretty much solve all of your writing needs with the methods we’ve discussed, but WSH provides us with one more method to make things even easier. It’s nice to be able to space out the text that we write to a text file, but it’s sometimes tedious to do using the Write and WriteLine methods.
object.WriteBlankLines(Int)
The WriteBlankLines methods will write a given number of consecutive newline characters to a file. It accepts a single required parameter, Int, which is an integer indicating how many newline character to write.
Note that the methods provided in this article can only write to TextStream objects. WSH does not provide any way natively to read or edit binary files.
The WriteBlankLines method is used in much the same way as the writing methods we’ve seen previously. Here’s a quick example.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\ScriptLog.txt", 2, 1)
objFile.WriteLine("This is our first line")
objFile.WriteBlankLines(3)
objFile.Write("This line is written after 3 blank lines")
objFile.Close
Here we’ve used the WriteBlankLines method to write three blank lines in our text file. The output should look like this:
This is our first line
This line is written after 3 blank lines
Next: Advanced writing concepts >>
More Windows Scripting Articles
More By Nilpo/Developer Shed Staff Writer