The best analogue I can think of to learn from would be a win32 read/write example. Some things need to be changed though still such as ActiveXObject instead of create object and no constants are defined so you have to explicitly assign these values. There may be an example somewhere around here. I'll see what I can dig up (getting son to sleep atm)
Javascript code:
function WriteDemo()
{
var fso, f, r
var ForReading = 1, ForWriting = 2;
fso = new ActiveXObject("Scripting.FileSystemObject")
f = fso.OpenTextFile("c:\\testfile.txt", ForWriting, true)
f.Write("Hello world!");
f.Close();
f = fso.OpenTextFile("c:\\testfile.txt", ForReading);
r = f.ReadLine();
return(r);
}
Hopefully you can use bits of that for what you want; it's all there
Although I'm sure there should be an f.Close(); before the return. This is taken from MSDN though
It can be put into two functions:
Javascript code:
function Write(filename, text){
try{
var fso = new ActiveXObject("Scripting.FileSystemObject")
f = fso.OpenTextFile(filename, 2, true)
f.Write(text);
f.Close();
return 1;
}catch(e){
Debug.Trace("Write Error: (File '"+filename+"': " + e.message);
return 0;
}
}
function Read(filename)
try{
f = fso.OpenTextFile(filename, 1);
return f.ReadLine();
}catch(e){
Debug.Trace("Read Error: (File '"+filename+"': " + e.message);
return 0; // Failed
}
}