Quick Tip: cffile action=”append” in cfscript

So this is old news - like ColdFuison 8 old news - but I've only started to use cfscript heavily with ColdFusion 9 so I just ran into this today. If you need to append to a file in cfscript you first need to use FileOpen() to open a file object in the append mode.

fileObj = FileOpen("/path/to/myfile.txt","append");

Then you can append to the file using FileWrite():

FileWrite( fileObj, "What ever is here gets appended.");

Note that unlike the default behavior of <cffile action="append"> FileWrite() does not append a newline character to text written to file.

Appending to a file isn't documented on the FileWrite() documentation for either ColdFusion 8 or ColdFuison 9, and the documentation does not list FileOpen() in the See Also section, so this took me a lot longer to figure out than it should have. Anyway, I hope this helps others making the transition from tag based to script based CFML.

Comments
Sam Farmer's Gravatar You should also do a fileClose when you are done: fileClose( fileObj );
# Posted By Sam Farmer | 2/1/11 4:26 PM
Nathan Mische's Gravatar Thanks Sam. FileClose() is also not documented in the FileWrite() documentation, and not shown in the FileWrite() example code, so I'm sure others will miss it as well.
# Posted By Nathan Mische | 2/2/11 8:50 PM
Cheap Juicy Couture's Gravatar If you're ready to have a baby as well as within being pregnant, you must certainly obtain coach outlet. Due to the fact these kinds of luggage supply you a variety of benefits to together by yourself plus your toddler, also they are stylish.
# Posted By Cheap Juicy Couture | 4/16/12 7:55 AM
BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.