By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,393 Members | 1,405 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,393 IT Pros & Developers. It's quick & easy.

searching a text and deleting the line

P: n/a
hello everybody,

i'm having some problems searching a text file and then deleting the line.
since i used fileopen(), i can use the eof() function to loop through the
file, searching for the specified line. the problem is, once found, i can't
delete it because the filemode is in openmode.input.
is there a way to chance the openmode on the run?(if so, what is it?)
and maybe there is a simpler way to search a text file and deleting the line?

this is the code so far:
<begin code>
Dim foto As String = fotos.Item(positionarray)
Dim arrayitem, line As String
FileOpen(4, cpath & albumpath & album, OpenMode.Input)
Do While Not EOF(4)
line = LineInput(4)
If line = foto Then
FileClose(4)
PrintLine(4, "")
MsgBox("deleted line!")
Exit Do
End If
Loop
FileClose(4)
<end code>
any help would be greatly appriciated :)

thanks,
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
In order to delete a line from a text file, you must read lines from
the file and write them to another file, except for the line you want
deleted. Once you complete the other file, you delete the original and
then rename the new one back to the original name.

Nov 21 '05 #2

P: n/a
You could use the replace word to search for the string you want and replace
it with an empty string "" , then over write the original file with the new
data

"angus" <an***@discussions.microsoft.com> wrote in message
news:1A**********************************@microsof t.com...
hello everybody,

i'm having some problems searching a text file and then deleting the line.
since i used fileopen(), i can use the eof() function to loop through the
file, searching for the specified line. the problem is, once found, i
can't
delete it because the filemode is in openmode.input.
is there a way to chance the openmode on the run?(if so, what is it?)
and maybe there is a simpler way to search a text file and deleting the
line?

this is the code so far:
<begin code>
Dim foto As String = fotos.Item(positionarray)
Dim arrayitem, line As String
FileOpen(4, cpath & albumpath & album, OpenMode.Input)
Do While Not EOF(4)
line = LineInput(4)
If line = foto Then
FileClose(4)
PrintLine(4, "")
MsgBox("deleted line!")
Exit Do
End If
Loop
FileClose(4)
<end code>
any help would be greatly appriciated :)

thanks,

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.