Append text to last line of a text file.

May 24, 2011 at 19:02:33
Specs: Windows XP
Greetings:

I am new to VB Scripting and have written a small script. The one area I am having a problem is when I want to add text to the last text line in a text file, not have the text added as a new line. For example if my text file contains.

This is line 1

When the script runs, I want the text that the script adds to the file to be added on to the last line of text in the file.
For example.

This is line 1. This is the new text that was added.


Instead I am getting
This is line 1.
This is the new text that was added.


The code I am using is:
dim filesys, filetxt
Const ForAppending = 8
Set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys1.OpenTextFile("c:\somefile2.txt", ForAppending, True)
filetxt.WriteLine ("and restored at " & Time() & ".")
filetxt.Close

Any help of suggestions would be appreciated.


See More: Append text to last line of a text file.

Report •

#1
May 24, 2011 at 19:38:44
Doesn't the command filetxt.WriteLine ("and restored at " & Time() & ".")
include an end of line character by default?


Report •
Related Solutions


Ask Question