REBOL [
Title: "Replace Text in Files"
Date: 26-Apr-1999
File: %replacetext.r
Purpose: {
To replace all occurrences of a string in a file with another string
}
]
replace: function [str tags [block!]][ptr][
foreach [tag symbol] tags [
str: head str
while [ptr: find str tag] [
str: insert (remove/part ptr (length? tag)) symbol
]
]
head str
]
replace-text: func [file-path [file!] file-pattern tags [block!] /local result][
dir: load file-path
foreach file dir [
if find file file-pattern [
write result: rejoin [file-path file] replace read result tags
]
]
]
Example: {
;Changes all occurrences of "December" with "January"
;and "1998" to "1999". Also removes all occurrences of
;"coming soon" found in all files containing ".html" in
;their name
replace-text %./ ".html" ["December" "January" "1998" "1999" "coming soon" ""]
}