Reputation: 1166
Anyone know how to quickly prepend (add two new lines of text) to the start of an existing text file using either VB Script or a Bat file? Most elegant solution gets the tick.
Upvotes: 3
Views: 3238
Reputation: 70324
Check José Basilios answer for code and reference to the FSO. You will be using that.
BUT: I wouldn't go the ReadAllTextFile = f.ReadAll
route, since that could be a few Gigabytes (who knows?).
INSTEAD:
Upvotes: 5
Reputation: 51488
How about this:
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("test.txt", 1)
ReadAllTextFile = f.ReadAll
Set f = fso.OpenTextFile("test.txt", 2, True)
f.WriteLine("Blaaa")
f.WriteLine("Blaaaa some more...")
f.Write(ReadAllTextFile)
Source: Tek Tips
Upvotes: 6