Task

Replace every occurring instance of a piece of text in a group of text files with another one.



For this task we want to replace the text   "Goodbye London!"   with   "Hello New York!"   for a list of files.




Const matchtext = "Goodbye London!"
Const repltext  = "Hello New York!"
Const matchlen  = Len(matchtext)
 
Dim As Integer x, L0 = 1
dim as string filespec, linein
 
L0 = 1
While Len(Command(L0))
    filespec = Dir(Command(L0))
    While Len(filespec)
        Open filespec For Binary As 1
        linein = Space(Lof(1))
        Get #1, 1, linein
        Do
            x = Instr(linein, matchtext)
            If x Then
                linein = Left(linein, x - 1) & repltext & Mid(linein, x + matchlen)
            Else
                Exit Do
            End If
        Loop
        Close
        Open filespec For Output As 1
        Print #1, linein;
        Close
        filespec = Dir
    Wend
    L0 += 1
Wend