searching a text and deleting the line

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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,
 
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.
 
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
 
Back
Top