Edit Anything

Professional text and hex editing
with Binary Templates technology.

SweetScape Knowledgebase
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.

     struct MYDATA
         int    id;
         string name; 
         double value;
         FPrintf( newFile, "%d, %s, %lf\n", id, name, value );
     MYDATA record1;

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

Our Products

Latest News

- 010 Editor
is now available.

Download it now!
What's New in 8.0?

Join our newsletter to receive tips and tricks on hex editing, special offers, and news from SweetScape Software Inc.

Sign-up Now...