<< Click to Display Table of Contents >> Navigation: 3. Script Language > Filesystem-Commands > Filesystem-Commands |
MiniRobotLanguage (MRL)
LOF. - Load-Text-File
Load Text File into internal Buffer for faster processing
Intention
When doing "Line-based" Operations on a Textfile, the use of LFF. (Line from File) can become slow.
Therefore the Combination of LOF. and LFT. was made. These Command-Pair works "in Memory".
Therefore you can access any Line of the Textfile immediately without any harddrive access.
This can speed up any Text-Processing significantly.
This command can be used together with the LFT. - command to process Text files faster.
Please also take a look at the TXT.-Commands. These Commands can be used, if there is more to do then just loading a file "Line by line".
It has two Working-Modes:
1.Load Text FIle into Buffer and return Index ($$IND):
LOF.$$IND|$$FIL
2. Remove Text File ($$IND is the Index) from Buffer
LOF.!$$IND
Currently you can load up to 128 Textfiles into the Buffer at the same time,
each having its own Index-Number from 1 to 128.
This is very good if you need to work on multiple Text-Files at the same time,
but you do not want to access the harddrive so often.
Using LOF. the file is buffered and all further Operations using LFT. are done in memory.
If you want to change or save the loaded Text-File, you need to transfer it to the TXT.-Command using:
VAR.$$FIL=?path\Test.txt
' Read the File into Memory
LOF.$$IND|$$FIL
' Transfer LOF.-Buffer to TXT.-Buffer clear LOF.-Buffer
TXT.gfl|$$IND
' Make all changes and save Text using the TXT.-Commands
TXT.Save
' Transfer Text back to LOF.-Buffer, clear TXT.-Buffer
TXT.tol|$$IND
Usage is simple:
VAR.$$FIL=?path\Test.txt
' Read the File into Memory
LOF.$$IND|$$FIL
'The Index Number for this file is now in $$IND
LFT.$$IND|-1|$$RET
'Using LFT. with " -1" as Linenumber, we get the Number of
'Lines in return (here in $$RET).
' Now we enumerate through the File without accessing
' the harddrive, at maximum Speed
FOR.$$LOP|1|$$RET
LFT.$$IND|$$LOP|$$LIN
PRT.$$LIN
NEX.
MBX.Ready
ENR.
Syntax
LOF.P1|P2
Parameter Explanation
P1 - (Variable) In this Variable the Index of the File is returned.
If P1 starts with a "!" then the FIle which is indexed by P1 will be
released from Memory. You do not need to release Files from memory,
this is done automatically when the Script ends.
P2 - Filename of the File to read.
Example
'********************************************
' Demo for LOF and LFT.
'********************************************
VAR.$$FIL=?path\Test.txt
LOF.$$IND|$$FIL
PRT.The Index Number for this file is >$$IND<
LFT.$$IND|-1|$$RET
PRT.Using LFT. with " -1" we get the Number of Lines.
PRT.Which is $$RET.
' Now we enumerate through the File without accessing
' the harddrive, at maximum Speed
FOR.$$LOP|1|$$RET
LFT.$$IND|$$LOP|$$LIN
PRT.$$LIN
NEX.
MBX.Ready
ENR.
Remarks
The current Limitation is that you can not load more then 128 Textfiles at the same time into Memory.
Also the delimiters must be $crlf$. If that is not the case, the Text-Files may be automatically converted when they are loaded.
For example, if there are only $CR in a File that is loaded, the Loader will add a $LF to each $CR so that in the Buffer you have a $crlf$ delimited FIle.
Limitations:
Currently you can load up to 128 Textfiles into the Buffer at the same time, each having its own Index-Number from 1 to 128. This is very good if you need to work on multiple Text-Files at the same time, but you do not want to access the harddrive so often. Using LOF. the file is buffered and all further Operations using LFT. are done in memory.
See also:
• IEF. / NEF. - If - exist - File