<< Click to Display Table of Contents >> Navigation: 3. Script Language > Filesystem-Commands > Filesystem-Commands |
MiniRobotLanguage (MRL)
CFI. Command
Copy from Inifile
Intention
This command is used to Read Entries from an INI-File. You can also read a full section from an INI-file. In case you want to read a whole INI-File, use the CFF.-command.
In short these are the four Modes of operation:
' Mode 1: Copies all Section-Names into Output-Var
CFI.Inifilename|Output-Var '
' Mode 2: Copies all Keys to Output-Var
CFI.Inifilename|Section|Output-Var
' Mode 3: Copies the specified Key to the Output-Var
CFI.Inifilename|Section|Key|Output-Var
' Mode 4: Copies the given Key to Output-Var, succes-flag to 0/1
CFI.Inifilename|Section|Key|Output-Var|Success-Flag
Mode 3 is the one that is most often used. You can read a value or string from an INI-File into a given variable.
Mode 4 is an enhancement of Mode 3. It gives you a flag that shows you if the operation was successful or not. This makes sense, because the result of the operation would be the same, whether the operation failed or the value was empty. See the example in the example -section below. The syntax is like that:
VAR.§§FIL=?desktop\one.ini
VAR.§§SEC=Section
VAR.§§KEY=Key
CFI.§§FIL|§§SEC|§§KEY|§§VAL|§§RES
MBX. We got this value from the INI-File: §§VAL
In Mode 1, all returned Section Names are separated by $crlf$. Therefore you can easily enumerate them using FEV.
Note that the Timeout-flag is also set according to the success of the operation. See the example below for a complete example that writes and reads an INI-File.
Syntax
CFI.P1|P2[|P3][|P4][|P5]
Parameter Explanation
P1 - Filename of Ini to write to
P2 - Section-Name
P3 - Key-Name*
P4 - (out) Value*
P5 - (out) Variable for Success-flag 1/0*
*Position of parameters differs according to Mode of operation, see explanation above. The last Parameter is always the return variable. See examples.
• CFI.Inifilename|Output-Var ' Copies all Section-Names
• CFI.Inifilename|Section|Output-Var ' Copies all Keys
• CFI.Inifilename|Section|Key|Output-Var
' Copies the given Key to Output-Var
• CFI.Inifilename|Section|Key|Output-Var|Success-Flag
' Copies the given Key to Output-Var, succes-flag to 0/1
Speed in Ticks:
This command uses typically around 4500 Ticks heavily depending on many factors like Filesystem-Speed and Parameters.
Example
'*****************************************************
' EXAMPLE 1: Enumerate INI-File
'*****************************************************
VAR.§§FIL=?desktop\one.ini
VAR.§§SEC=Section
VAR.§§KEY=Key
VAR.$$BLO=ABCDEFGHIJ
VAR.§§VAL=MyValue
' First we write to a ini-file
FOR.§§CNT|1|3
: §§SEA=§§SEC_§§CNT
FOR.§§CNX|1|5
DBP.§§SEA
CTI.§§FIL|§§SEA|§§KEY_§§CNX|§§VAL#dtime#|§§RES
IVV.§§RES=1
DBP. Ini was written with success!
ELS.
DBP. Ini was NOT written with success!
EIF.
NEX.
NEX.
' Now we read all Section-Names
CFI.§§FIL|§§MYS
PRT.Section-Names:$crlf$§§MYS
FEV.doit|§§SKA|§§MYS
MBX.Ready
ENR.
:doit
' Get all Keys from that section
CFI.§§FIL|§§SEA|§§MYK
PRT.Key-Names from §§SKA:$crlf$§§MYK
' Enumerate all Keys also
PRT. Key-Enumeration:
FEV.doitb|§§SIK|§§MYK
RET.
:doitb
CFI.§§FIL|§§SKA|§§SIK|§§VAL
PRT. Key: §§SIK Value=§§VAL
RET.
'*****************************************************
' EXAMPLE 2: CTI./CFI. Write/Read INI-File
'*****************************************************
VAR.§§FIL=?desktop\one.ini
VAR.§§SEC=Section
VAR.§§KEY=Key
VAR.$$BLO=ABCDEFGHIJ
' Generating a string of length ~80000 ...
§§VAL=$$BLO
FOR.$$CNT|1|12
VAR.§§VAL=$$BLO§§VAL§§VAL
NEX.
GSS.1|65530|§§VAL|§§VAL
LEN.§§VAL|$$RES
DBP.Trying to write a string of Len=$$RES to INI.
' First we write to a ini-file
FOR.§§CNT|1|3
: §§SEA=§§SEC_§§CNT
FOR.§§CNX|1|5
DBP.§§SEA
CTI.§§FIL|§§SEA|§§KEY_§§CNX|§§VAL|§§RES
IVV.§§RES=1
DBP. Ini was written with success!
ELS.
DBP. Ini was NOT written with success!
EIF.
NEX.
NEX.
' Now we read all Section-Names
CFI.§§FIL|§§MYS
PRT.Section-Names:$crlf$§§MYS
: §§SEA=Section_1
CFI.§§FIL|§§SEA|§§MYT
PRT.Key-Names:$crlf$§§MYT
MBX.Ready
ENR.
Remarks
In Mode 1+2, all returned Section and Key Names are separated by $crlf$. Therefore you can easily enumerate them using FEV.
Limitations:
The maximum length of values to be read from an INI-File is is 65535 Bytes.
See also:
• IEF. / NEF. - If - exist - File