-
January 28th, 2004, 10:00 PM
#1
remove a line in file
Dear Sir,
I would like to remove 1 line in file (.txt).This line will in the last line of the file.I'm not sure how to do it. Please help me.
Thanks
-
January 28th, 2004, 11:44 PM
#2
I don't think u can delete a line from text file.
I had same problem and i copy line by line to another text file by ignoring the line which I want to delete
-
January 29th, 2004, 12:11 AM
#3
The only way to do that to my knowledge is to read the whole file
then rewrite it skipping the last line.
Code:
Private Sub RemoveLastLine(ByVal sFile As String)
Dim fileData As Variant
Dim temp As String
Open sFile For Binary Access Read As #1
temp = Space(LOF(1))
Get #1, , temp
Close #1
fileData = Split(temp, vbCrLf)
Open sFile For Output As #1
For X = LBound(fileData) To UBound(fileData) - 1
Print #1, fileData(X)
Next
Close #1
End Sub
-
January 29th, 2004, 09:55 AM
#4
Jinto's code seems to be doing exactly what you are looking for. Read in the whole file, and rewrite the file leaving out the last line.
BTW, if you need to delete a specified line from a text file you can use the code in this link http://www.freevbcode.com/ShowCode.asp?ID=2667
I used it and modified it to suit my own requirements.
Cheers,
Laurent
For an aviator, the three best things in life are a good landing, a good orgasm, and a good sh*t. A night carrier landing is one of the few opportunities to experience all three at the same time.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|