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):
| || || |
| || |
| || || |
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.
Looking For A New Job?
- Mobile Application Developer at Xorbia Tickets
- 7 Year + Lead ColdFusion Developer at Atprime Media Services
- Full Time ColdFusion Developer Needed at InterCoastal Net Designs
- Developer-focused job platform at Honeypot