<< Click to Display Table of Contents >> Navigation: 3. Script Language > Filesystem-Commands > FIL. - File-Commands > FIL. - File-Commands |
MiniRobotLanguage (MRL)
FIL.Append to File
Append to File
Intention
This command is useful for writing log files.
It will append any content (text or binary) to an existing file. If the file does not already exist, it will create a new one.
Unlike the previous ATF. command, FIL.Append to File first writes to a temporary file before replacing the original file.
This ensures that the original file is not corrupted if the operation is interrupted.
This makes the process rather slow compared to the Simple "ATF."-Command.
Because this file will copy the complete file for any Append-Operation, due to safety considerations,
prefer the normal "ATF." Commands for standard-Usage where Speed is more important then Safety.
Please note that FIL.Append to File does not append newline characters ($crlf$) automatically.
This must be done manually if needed.
Syntax
FIL.Append to File|P1|P2[|P3]
Parameter Explanation
P1 - Filename or path of the file to be appended to.
P2 - Text or data to be appended.
P3 - (optional) - Variable which receives 1 if the operation was successful, or 0 if it failed.
Example
'*****************************************************
' EXAMPLE 1: FIL.Append to File with Newlines
' Create a logfile on your desktop
'*****************************************************
'DBM.2
' This is the filename and path on the desktop
: $$FIL=?desktop\RND.txt
FOR.$$AAA|1|20
' Generate a Random Number between 124 and 123125
RND.124|123125|$$REB
' Here comes the Newline
VAR.$$REB=$date$ ** $time$> The Number is: $$REB$crlf$
' Append the Numbers to the File without Newline
FIL.Append to File|$$FIL|$$REB|$$ERG
PRT.[$$AAA]->$$ERG
NEX.
MBX.Please see the File $$FIL on your desktop.
END.
In the example, we generate a random number between 124 and 123125 for 20 times. Each number, along with the current date and time, is appended to a file on the desktop.
The FIL.Append to File command is used to append the data to the file, and the result of each append operation is printed to the console. At the end of the script, a message box appears, indicating the location of the file on the desktop.
Remarks
-
Limitations:
-
See also:
• IEF. / NEF. - If - exist - File