BE_FileWriteText

BE_FileWriteText ( pathOrContainer ; text {; appendBoolean } )

Writes the contents specified in text to the file at the path. Using the optional appendBoolean parameter you can choose to either write a new file ( or overwrite an existing one ), or to append the text to the end of the file.

Defaults to UTF-8 ( no BOM ) which can be changed using the BE_SetTextEncoding function.

Version : 1.0
1.1 : Adds appendBoolean option.
3.3 : Recursively create any directories needed.
4.0.2 : Renamed from BE_WriteTextToFile - now allows writing to container fields as well as paths.

Parameters : 


pathOrContainer : a system file path. (for example, "/Users/johndoe/Documents/helloworld.txt" on OS X or "C:\Users\johndoe\Desktop\helloworld.txt" on Win7) 
text : the contents to write to the file. 
append ( optional ) : True or False - True will append to the file, False or no parameter will either write over an existing file or set the contents of a new file.

Result : 0 on success, ? for an invalid path and a OS error code on failures.

Notes on working with containers

For writing files to containers, this function works a little differently.  First you need to use this as a Set Field step, not a Set Variable, or as some other part of a calculation.  The resulting output will then be set into the file.  

  • If you're appending to a file, and setting it into a field, the first parameter pathOrContainer can be either a field with an existing file, or a path to an existing file.  The result will then be appended to the original.  Set the appendBoolean parameter to True.
  • If you're setting a field and not appending, the first parameter should contain just the name of the file you want as text.

Obviously this first parameter can be many things, a path, a container field containing a file, or a text string ( from a field, or variable etc ) containing a file name.  So double check the code you use, to make sure it's got the correct info.

Still need help? Contact Us Contact Us