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.

Newsletter - Receive special offers, tips, tricks and news. Join now

010 Editor v14.0.1 is here!
What's new?



010 Editor

E-mail: info@sweetscape.com