Reading the contents of a file:
(This code contains no error handling - you're expected to add it yourself)
- See note below on file paths.
code:
function get_file_contents(file)
{
var fileSys = new ActiveXObject("Scripting.FileSystemObject");
var fileH = fileSys.OpenTextFile(file, 1, 0);
var text = fileH.ReadAll();
fileH.close();
return text;
}
Checking if a file exists:
- See note below on file paths.
code:
function file_exists(file)
{
var fileSys = new ActiveXObject("Scripting.FileSystemObject");
if(fileSys.FileExists(file))
{
return true;
}
else
{
return false;
}
}
Note:
You need double slashes in the path - ex, C:\\test\\file.txt.
Also - when reading files, the base path is actually your windows profile directory (C:\Documents and Settings\....). If you need to read something from your scripts directory, then you would use:
myFile = MsgPlus.ScriptFilesPath+"\\file.txt";