FileAppend

Description

Appends text or contents of an object to an in-memory text file.

You can also use this function as an alternative to the cffile tag with the action="append" attribute.

Returns

Void.

Category

Function Syntax

FileAppend(file, data[, charset, addNewLine])

See also

History

ColdFusion (2018 release) Update 4, ColdFusion (2016 release) Update 11: Added support for this function.

Parameters

Parameter

Required (Yes/No)

Description

file

Yes

An absolute path to an on-disk or in-memory text file on the server.

data

Yes

The file object or string from which to read.

charset

No

The character encoding in which the file contents is encoded. The following list includes commonly used values:

  • utf-8
  • iso-8859-1
  • windows-1252
  • us-ascii
  • shift_jis
  • iso-2022-jp
  • euc-jp
  • euc-kr
  • big5
  • euc-cn
  • utf-16
    If the file starts with a byte order mark and you set this attribute to a conflicting character encoding, ColdFusion generates an error.

addNewLine

No

Boolean value that indicates whether a new line is to be added to the contents of the file.

Example

<cfscript> 
    theDir=GetDirectoryFromPath(GetCurrentTemplatePath()) 
    theFolder=theDir & "file.txt" 
    fileData="The quick brown fox jumps over the lazy dog." 
    FileAppend(file=theFolder,data=fileData,charset="UTF-8",addNewLine="yes") 
</cfscript>

In the snippet above, the parameter addNewLine adds the information that is specified in the parameter data. As many times you run this snippet, the information gets added as a new line in the output file.

 Adobe

Get help faster and easier

New user?