Opening a file and removing previous 2 lines

garcon

Well-known member
Joined
Dec 13, 2004
Messages
47
Programming Experience
Beginner
Folks,


I want to open a file and remove the previous 2 lines and then write a new line. I know how to do the last bit i.e. adding the last line:

VB.NET:
[size=2][color=#0000ff]Dim[/color][/size][size=2] fileName [/size][size=2][color=#0000ff]As[/color][/size][size=2][color=#0000ff]String[/color][/size]
[size=2]fileName = "C:\afile.txt"[/size]
[size=2]Microsoft.VisualBasic.FileSystem.FileOpen(1, fileName, OpenMode.Append)
WriteLine(1, String1, String2, String3, String4)
 
FileClose(1)
[/size]

Can anyone help? How do you delete the previous 2 lines? Any suggestions/comments/ideas - much appreciated... - thanks.

Confused,
G.
 
I belive your doing it the VB 6 way, use system.io.streamread/write. As for removing the last 2 lines, you could read it into a string remove the 2 lines then write it back to the file. I'm not aware of a direct way of deleting lines.

TPM
 
Back
Top