Searching for a string:
What this does is it searches a file at %path for an instanced of %string using strPos. More specifically, it checks each line with strPos, and if it finds the %string it returns 1 (true). If it gets to the end of the file (isEOF()), it will return 0 (false). You could even edit this to return the %path of the file if it finds it, if you're making a search-esque function. In which case, you should also edit the last return to -1 to check for no file found.
function searchFileForStr(%path,%string) {
%file=new FileObject();
%file.openForRead(%path);
while(!%file.isEOF()) {
if(strPos(%file.readLine(),%string)!=-1) {
%file.close();
%file.delete();
return 1;
}
}
%file.close();
%file.delete();
return 0;
}
Creating a file if it doesn't exist:
By putting this in your file code, you will be using isFile() to check if a file at the path exists. If not, it creates a blank file at the path with no contents. After closing the file it moves on to the next file events you may have.
%path="config/server/exampleFile.txt";
%file=new FileObject();
if(!isFile(%path)) {
%file.openForWrite(%path);
%file.writeLine(" ");
%file.close();
}
//> Other file events go here
%file.delete();
Warning - while you were typing a new reply has been posted. You may wish to review your post.Hunter :3
EDIT:
For replacing a bit of text in a file, look at the script I used for the
Saving Variables add-on.