cffile in cfscript quick cheat sheet

First time for using CFFILE within cfscript so thought I should document this for myself and anyone else.

Open and close a file

view plain print about
1myFile = expandPath( "somefile.txt" );
2fileObj = fileRead( myFile );
3writeOutput(fileObj);
4// OR
5myFile = expandPath( "somefile.txt" );
6fileObj = fileOpen( myFile, "read" );
7fileClose( fileObj ); // Once a file is closed you cannot access the object

Posted: 10-Jun-2010

View: 4922

Permalink: here

Comments

This may fall into the category of "No Duh", but you can also use these functions in tag based CF as well. I don't like how verbose cffile is - so if I want to simply read in a file, I may do:

<cfset contents = fileRead("..")>

#1 Raymond Camden
10/Jun/10 3:20 PM

I use this cheat sheet quite frequently. Thanks for putting it together.

#2 Evik James
15/Nov/10 10:33 PM

@evik cheers. Its good to know its helped someone

#3 Andy Jarrett
17/Nov/10 9:29 AM