Skip to main content
Ben Nadel at cf.Objective() 2010 (Minneapolis, MN) with: Doug Hughes and Ezra Parker and Dan Wilson and John Mason and Jason Dean and Luis Majano and Mark Mandel and Brian Kotek and Wil Genovese and Rob Brooks-Bilson and Andy Matthews and Simeon Bateman and Ray Camden and Chris Rockett and Joe Bernard and Dan Skaggs and Byron Raines and Barney Boisvert and Simon Free and Steve 'Cutter' Blades and Seth Bienek and Katie Bienek and Jeff Coughlin
Ben Nadel at cf.Objective() 2010 (Minneapolis, MN) with: Doug Hughes Ezra Parker Dan Wilson John Mason Jason Dean Luis Majano Mark Mandel Brian Kotek Wil Genovese Rob Brooks-Bilson Andy Matthews Simeon Bateman Ray Camden Chris Rockett Joe Bernard Dan Skaggs Byron Raines Barney Boisvert Simon Free Steve 'Cutter' Blades Seth Bienek Katie Bienek Jeff Coughlin

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

By
Published in

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:

<cfscript>

	// 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-" );

</cfscript>

... 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

I believe in love. I believe in compassion. I believe in human rights. I believe that we can afford to give more of these gifts to the world around us because it costs us nothing to be decent and kind and understanding. And, I want you to know that when you land on this site, you are accepted for who you are, no matter how you identify, what truths you live, or whatever kind of goofy shit makes you feel alive! Rock on with your bad self!
Ben Nadel
Managed hosting services provided by:
xByte Cloud Logo