Book a Demo

Author Topic: How to read source file?  (Read 5048 times)

survex

  • EA User
  • **
  • Posts: 76
  • Karma: +1/-1
    • View Profile
How to read source file?
« on: November 19, 2014, 08:10:00 am »
Say, I have reversed engineered model. Source code has some comments:
// @tag=value
So I want to read all source files of all classes looking for some pattern and creating taggedValues.
But how? How can I read file using EA scripting?

survex

  • EA User
  • **
  • Posts: 76
  • Karma: +1/-1
    • View Profile
Re: How to read source file?
« Reply #1 on: November 19, 2014, 07:57:53 pm »
Found the answer:

Code: [Select]
!INC Local Scripts.EAConstants-JScript
 
function main()
{
      Repository.EnsureOutputVisible("Script");
      
      var classElement = Repository.GetElementByGuid("XXX");
      
      Session.Output(classElement.Genfile);
      
       var fso = new ActiveXObject("Scripting.FileSystemObject");
    f = fso.OpenTextFile(classElement.Genfile, 1);
    // Read from the file and display the results.
    while (!f.AtEndOfStream)
    {
        var r = f.ReadLine();
        Session.Output(r);
    }

    f.Close();
      Session.Output( "Done!" );
}

main();