I need help with seeking to the end of a file, deleting a line and saving the file. Below is my windows text file and my code so far.
Windows Text File
102,,agent_disconnect,2007-02-27 22:54:44,0xffffffff,0xffffffff,,,,000.184.00.131,000.184.00.131,,,,,,,,,,,,
102,,agent_disconnect,2007-02-27 22:54:44,0xffffffff,0xffffffff,,,,00.109.000.010,00.109.000.010,,,,,,,,,,,,
102,,agent_discon
------------------------
Code:
//Goal: read to end of file and delete the last line, then save the file as win.txt
Dim myFile As String
myFile = "c:\logfiles\winlog.txt"
Dim fs As New FileStream("myFile", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)
fs.Seek(0, SeekOrigin.End)
'read back and remove the last line?
'now save as new file in c:\logfiles\temp\win.txt
fs.Close()
http://msdn2.microsoft.com/en-us/library/system.io.filestream.setlength.aspx
"If the given value is less than the current length of the stream, the stream is truncated."
I haven't tied it myself...but maybe:
fs.SetLength(currentPositi
fs.Close()