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.




$matchtext = "Goodbye London!"
$repltext  = "Hello New York!"
 
FUNCTION PBMAIN () AS LONG
    DIM L0 AS INTEGER, filespec AS STRING, linein AS STRING
 
    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
                ' No need to jump through FB's hoops here...
                REPLACE $matchtext WITH $repltext IN linein
                PUT #1, 1, linein
                SETEOF #1
            CLOSE
            filespec = DIR$
        WEND
        INCR L0
    WEND
END FUNCTION