Skip to main content
Ben Nadel at CFUNITED 2009 (Lansdowne, VA) with: Katie Maher
Ben Nadel at CFUNITED 2009 (Lansdowne, VA) with: Katie Maher

Use A GetTempFile() Prefix That Links The File Back To The Code That Created It

By on

When you use the getTempFile() function, in ColdFusion, you can provide a prefix that will be used in the generated filename. According to the ColdFusion documentation, only 3-characters of this prefix value will be used. However, this is often misleading. I suggest using a prefix that contains information sufficient to link the file back to the code that created it.

I've developed ColdFusion applications on both Windows and *nix machines and I've never seen ColdFusion actually truncate a prefix that I've given to the getTempFile() function. As such, I've developed a habit of creating long [enough] prefix values that clearly indicate what portion of the code-base created the temporary file.

When we run this code:


	// Explore the use of long getTempFile() prefix values.
	getTempFile( getTempDirectory(), "bn-processing-asset-id-4-" );
	getTempFile( getTempDirectory(), "bn-importing-excel-document-16-" );
	getTempFile( getTempDirectory(), "bn-exporting-monthly-report-91470342014081-csv-" );


... we create the following temporary files (on my local Mac):

getTempFile() function in ColdFusion can use a long prefix.

As you can see, none of the prefix values were truncated - not even the one that contains 47 characters.

Personally, I'm not a huge fan of the getTempFile() function. Most of the time, I create a UUID (Universally Unique Identifier)-based scratch directory in which uniqueness is no longer a concern. But, if and when I do use the getTempFile() function, I always make sure to use a prefix that clearly indicates from where in the code-base it originated.

Want to use code from this post? Check out the license.

Reader Comments