Forum Discussion

ngalchenko's avatar
ngalchenko
New Contributor
11 years ago
Solved

TestComplete - Can't read .ini file added to the Stores Files Collection, if file is located in folder other then root C:\ folder.


I can't read .ini file added to the Stores Files Collection, if file is located in folder other then root C:\ folder.

Please help.



I am using JScript. Below is more details:



1. I created file C:\MyFolder\config123.ini

; IMPORTANT: The Root section is mandatory

[Root]



[Settings]

URL=http://localhost.com/

ServerName=MyServer



2. I manually added this file to Stores File collection.



3. I have script in JScript:

function Main()

{

  var ini, URL,SQLServerName;

  ini = Storages.INI("C:\\MyFolder\config123.ini");

  URL = ini.GetSubSection("Settings").GetOption("URL", "");

  SQLServerName=ini.GetSubSection("Settings").GetOption("ServerName", "");

}



4. I set breakpoint on line SQLServerName=ini.GetSubSection("Settings").GetOption("ServerName", "");



5. When I execute this script .ini object doesn't return my .ini file I and URL="", wich is incorrect.



Interesting enough if I copy .ini file to root folder C:\ , change code ini = Storages.INI("C:\\config123.ini");

I am getting proper URL and ServerName values even if I delete file from Stores File collection.



I think that I follow manuals, why am I not getting expected result? Please help.



Thank you



Natalya


  • Hi Natalya, you appear to have missed an escaping "\", between MyFolder and config123 i.e.



    ini = Storages.INI("C:\\MyFolder\config123.ini"); should be

    ini = Storages.INI("C:\\MyFolder\\config123.ini");



    Also, as you have the ini file in the Files Store, I would recommend using the Files::FileNameByName()  method to pass in the path to Storages::INI() method to avoid these issues in future, e.g.



    ini = Storages.INI( Files.FileNameByName( "AMITestConfiguration_INI" ) );



    where "AMITestConfiguration_INI" is the name in Files of the ini file you wish to process



    Regards,

    Phil Baird

4 Replies

  • Philip_Baird's avatar
    Philip_Baird
    Community Expert
    Hi Natalya, you appear to have missed an escaping "\", between MyFolder and config123 i.e.



    ini = Storages.INI("C:\\MyFolder\config123.ini"); should be

    ini = Storages.INI("C:\\MyFolder\\config123.ini");



    Also, as you have the ini file in the Files Store, I would recommend using the Files::FileNameByName()  method to pass in the path to Storages::INI() method to avoid these issues in future, e.g.



    ini = Storages.INI( Files.FileNameByName( "AMITestConfiguration_INI" ) );



    where "AMITestConfiguration_INI" is the name in Files of the ini file you wish to process



    Regards,

    Phil Baird
  • ngalchenko's avatar
    ngalchenko
    New Contributor


    Phil, thank you for your quick response! You are absolutely right, "\" is missing.

    Thank you for your recommendation too, I really appreciate it!



     



    Natalya


    • ademin's avatar
      ademin
      Senior Member

      it seems like Storages.INI will not work if ini file does not have [Root] section

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        You are correct.  Storages.INI requires the INI file to have a particular format, namely that there is a [Root] section.