Create A Unique Filename When Moving With CFFile

Published: {ts '2013-04-30 00:00:00'}
Author: Steven Neiland
Site Url: http://www.neiland.net/article/create-a-unique-filename-when-moving-with-cffile/

It would seem obvious that the move action for cffile should give you the option to create a unique filename if the destination directory already contains a file with the same name. It would seem. Yet ColdFusion does not.

So here is a function I put together for a project a while back to do this for me.

Note: While not strictly necessary the cflock is an added guarantee that this code does not encounter a race condition when moving files into a specific directory.