I don't like looking back and seeing my Code Library entries being really outdated and some not even working anymore, so I'll start updating them I suppose!
To start off, I've made this function more reliable in it's behaviour. The old code tended to randomly skip text to replace.
PHP Code:
function replaceTxt(pre, past)
{
temp.header = "mal_"; // Anti never ending while (...) loop
temp.allowedExt = { ".nw" }; // Will skip all files but these
temp.folderPath = "levels/levels/"; // Base folder
temp.checkSubs = true; // Scan through subfolders too?
temp.folder.loadFolder(temp.folderPath @ "*", temp.checkSubs);
echo("Starting scan on" SPC temp.folder.size() SPC "files...");
temp.totalLevelChanges = NULL;
for (temp.file: temp.folder) {
if (!(extractfileext(temp.file) in temp.allowedExt))
continue;
temp.file = findfiles(extractfilename(temp.file), true)[0];
temp.lines = "";
temp.lines.loadString(temp.file);
// Times replaced this level
temp.currentLevelChanges = NULL;
while (temp.lines.pos(pre) > -1) {
temp.pos = temp.lines.pos(pre);
if (temp.lines.substring(temp.pos - temp.header.length(), temp.header.length()) == temp.header)
break;
temp.lines = temp.lines.substring(0, temp.pos) @ past @ temp.lines.substring(temp.pos + pre.length());
temp.currentLevelChanges ++;
temp.totalLevelChanges ++;
}
if (temp.currentLevelChanges != NULL) {
echo("Replaced text" SPC temp.currentLevelChanges SPC "times in" SPC temp.file @ "!");
temp.lines.savestring(temp.file, false);
}
}
echo("Done! Replaced text a total of" SPC temp.totalLevelChanges SPC "times!");
}
If a mod would be so kind to update the first post... <3