/*
// The following should be included at the top of your source file to
// enable "Include" functionality.
// At some point, I will enable this to work with the INC environment
// variable.
var fso = WScript.CreateObject("Scripting.FileSystemObject");
var f = fso.OpenTextFile("Include.js", 1);
var str = f.ReadAll();
f.close();
eval (str);
// Once you have the above, you can use:
eval(Include("Filename"));
// OR
var fso = WScript.CreateObject("Scripting.FileSystemObject");
var f = fso.OpenTextFile("Include.js", 1);
var str = f.ReadAll(); f.close(); eval (str);
eval(Include("SomeOtherFile.js"));
// Of course if all you are going to do is include one file, then
// substitute that filename for "Include.js" instead.
*/
function Include(Filename)
{
var str;
var fsoInclude;
var otf;
try
{
if (typeof(fso) == "undefined")
{
fsoInclude =
WScript.CreateObject("Scripting.FileSystemObject");
}
else
{
fsoInclude = fso;
}
otf = fsoInclude.OpenTextFile(Filename, 1);
str = otf.ReadAll();
}
catch(objError)
{
WScript.Echo("Error reading the file " + Filename);
if (objError.name != "Error")
{
WScript.Echo("Error name: " + objError.name);
}
WScript.Echo("Error number: " + objError.number);
WScript.Echo("Error description: " + objError.description);
if (objError.message != objError.description)
{
WScript.Echo("Error message: " + objError.message);
}
throw(objError);
}
finally
{
if (typeof(otf) != "undefined")
{
otf.close();
}
fsoInclude = null;
}
return str;
}