Skip to main content
Ben Nadel at Scotch On The Rock (SOTR) 2010 (London) with: James Padolsey
Ben Nadel at Scotch On The Rock (SOTR) 2010 (London) with: James Padolsey

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