Reading multiple files using eval
Hi All ,
I have 2 files to be included from commonfiles folder as shown in main(). How do i read both in my include function ?. Please look into this.
function main()
{
eval(Include("..\\..\\CommonFiles\\GlobalConstants.js"));
eval(Include("..\\..\\CommonFiles\\WindowsConstants.js"));
}
function Include(filepath)
{
var objfSO = new ActiveXObject("Scripting.FileSystemObject");
var readFile = objfSO.OpenTextFile(filepath, 1);
while(!readFile.AtEndOfStream){
var readLine = readFile.ReadLine();
Log.Message(readLine);
}
readFile.Close();
return readLine;
} // End Include()
Hi Vinod,
Your reading function looks ok. What issues do you observe?
BTW, if you want to execute a script file, you can call the Run or Exec method of the WScript.Shell object. For example:
// JScript var file = "c:\\1.js"; var WshShell = new ActiveXObject("WScript.Shell"); var oExec = WshShell.Exec(file);
Hi Tanya ,
The Include function have ReadLine() . and i am returning the ReadLine which is finaly returning the last line read. and thats when it starts giving the sysntax error. So i changed it to ReadAll() and returned the whole content and it started working fine. I also read the content after returning and it is printing correct message.
function main()
{
eval(Include("..\\..\\CommonFiles\\AppResourceIDs.js"));
eval(Include("..\\..\\CommonFiles\\WindowsConstants.js"));
Log.Message("The value of IDD_TIP is : " + ControlId.IDD_TIP);
Log.Message("The value of IDIGNORE is :" + WindowsControlId.IDIGNORE);
}
function Include(filename)
{
var forReading = 1;
var fileContent;
var objFile = new ActiveXObject("Scripting.FileSystemObject");
var readFile = objFile.OpenTextFile(filename, forReading);
while(!readFile.AtEndOfStream){
fileContent = readFile.ReadAll();
}
readFile.Close();
return fileContent;
} // End Include()