KB1004: How can I output data to a file while running a Template?
A Binary Template cannot modify the bytes of the file it is being run on; however, a
Template can open a new file with the function 'FileNew' and then write data to this new file.
For example, use the following code at the beginning of a template to create a new file:
local int newFile = FileNew();
Then the 'FPrintf' function can be used to write data to this file
(this function is available in version 2.0 and higher). The following example declares
a type 'MYDATA' and everytime a variable of this type is defined, a new line
is written out to the text file.
FPrintf( newFile, "%d, %s, %lf\n", id, name, value );
The above example writes a comma-delimited file but if you with to write a tab-delimited
file use '\t' instead of ',' in the FPrintf function. If you wish to
modify the bytes of the current file, you can use a Script to edit the variables that
were defined in the Template.
Back to knowledgebase index
Back to main support page