troubleshooting Question

seek to end of file, delete line

Avatar of fwsteal
fwsteal asked on
Visual Basic.NET
6 Comments1 Solution352 ViewsLast Modified:
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,,,,,,,,,,,,,,,,,
102,,agent_disconnect,2007-02-27 22:54:44,0xffffffff,0xffffffff,,,,,,,,,,,,,,,,,

//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
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 6 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros