CONFIGLOAD Load a section from a configuration file |
Top Previous Next |
Use this script command to read in and store key/value pairs from a section in a configuration file. It creates an associative array where the key and value for each array element is set to the key and value, respectively, read from the configuration file.
This command is for working with external configuration files. This can not be used for reading values from Robo-FTP's internal settings files.
For example, let's say you have the following configuration file in the current working directory named "my_config.ini."
[My First Section] a_setting = some value another_setting = some other value
You can load the values from "My First Section" into a variable with the following command:
CONFIGLOAD "my_config.ini" "My First Section" my_properties DISPLAY my_properties[*] ;; Set to the number of properties (2 in this case) DISPLAY my_properties[a_setting] ;; Set to 'some value' DISPLAY my_properties[another_setting] ;; Set to 'some other value'
If a configuration file has settings at the top that are not under a section heading, Robo-FTP will create an element in the array for that unnamed section and set it to an empty string. For example:
property_not_under_a_section = a value [First Section] first_property = some value second_property = some other value
In this case, the following command will read the property from the unnamed section:
CONFIGLOAD "my_config.ini" "" my_properties DISPLAY my_properties[*] ;; Set to the number of properties (1 in this case) DISPLAY my_properties[property_not_under_a_section] ;; Set to a value'
This script command also supports an alternate syntax where, if the third command argument is omitted, then a global variable is created for each key/value pair from the specified section in the configuration file.
This alternate syntax is not recommended for production use as there are potential risks from creating global variables based on the contents of an external file. This alternate syntax may be deprecated and removed in a future release.
For example, let's say you have the following configuration file in the current working directory named "my_config.ini."
[My First Section] a_setting = some value another_setting = some other value
You can load the values from "My First Section" from the configuration file into global variables with the following command:
CONFIGLOAD "my_config.ini" "My First Section" DISPLAY a_setting ;; Set to 'some value' DISPLAY another_setting ;; Set to 'some other value'
Related command(s): CONFIGSECTIONS See also: Working with External Configuration Files, Arrays |