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