Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete first line from txt file

Status
Not open for further replies.

61cygni

IS-IT--Management
Jul 16, 2002
16
0
0
GB
Hi,

I'd like to delete the first line of a text file from the click of a button.

Hope someone can help

Regards,

Steve K
 
i would recommend reading in the text file, get the index of the first vbcrlf and removing all text up to this point. If you need more guidance let me know and i will give you some code
 
Hi,

If you could provide some code that'd be very helpful

Regards,

Steve K
 
Hi,

its fridayt afternoon and time to go home, so i only write a little code for you, it essentially opens the file and removes the text until the first vbcrlf, so all you have to write is the part to overwrite the existing file, sorry i couldnt finish it, but its the weekend :)


Dim myFile As File
Dim strFile As String
Dim sr As StreamReader = myFile.OpenText("c:\myfile.txt")
strFile = sr.ReadToEnd
sr.Close()

strFile = strFile.Substring(strFile.IndexOf(vbCrLf) + 1)
 
thank-you very much that's a big help. Hope you have a nice weekend
 
Completed code

Dim myFile As File
Dim strFile As String

Dim sr As New System.IO.StreamReader("C:\label.txt")
strFile = sr.ReadToEnd
sr.Close()

strFile = strFile.Substring(strFile.IndexOf(vbCrLf) + 1)

Dim sw As New System.IO.StreamWriter("C:\label.txt")
sw.WriteLine(strFile)
sw.Close()
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top