<< Click to Display Table of Contents >> Navigation: 3. Script Language > Filesystem-Commands > FIL. - File-Commands > FIL. - File-Commands |
MiniRobotLanguage (MRL)
FIL.Insert in File
Inserts a string into a file at a specified position.
Intention
The FIL.Insert in File command is used to insert a specific string into a file at a specified position.
This command is particularly useful when you need to modify a file without reading the entire file into memory, which makes it suitable for working with large files.
To insert the string "Hello World" at position 100 in a file named "example.txt", and store the result in a variable named "$$RES", you would use the following command:
FIL.Insert in File|Hello World|c:\example.txt|100|$$RES
MBX.$$RES
This command will insert the string "Hello World" at the 100th byte of the file "example.txt".
If the operation is successful, the command will return 0 in the variable "Result".
This command works by creating a temporary copy of the file, making the necessary modifications, and then replacing the original file with the modified copy.
This ensures that the original file is not corrupted if the operation is interrupted. However, this also means that the command requires enough free disk space to store the temporary copy of the file.
If there is not enough free disk space, the command will fail with an error.
Syntax
FIL.Insert in File|P1|P2|P3[|P4]
FIL.IIF|P1|P2|P3[|P4]
Parameter Explanation
•P1 - The string to be inserted into the file.
•P2 - The file name or path of the file to be modified.
•P3 - The position in the file where the string should be inserted.
•P4 (optional) - The variable to store the return code of the operation. The command returns a numeric code indicating the result of the operation:
•0 - The operation was successful.
•1 - An error occurred while opening the file.
•2 - An error occurred while writing to the file.
Example
'***********************************
'
'***********************************
Remarks
-
Limitations:
-
See also:
• IEF. / NEF. - If - exist - File