I needed to copy a directory and all of files within it today. My first thought was that I should be able to do this in cfdirectory, but no luck there. I then hoped I could cheat and use cffile to copy a directory as though it were a file, but no luck there either. I knew that I could write some recursive code to copy the cirectory and all of its contents, but I felt there should be an easier way.
As an aside, Joe Rinehart wrote a really good directoryCopy() UDF that would have solved my problem if only I had thought to look. The lesson is to always check cflib.org when trying to solve a common problem.
Anyway, I did think of a way to solve the problem without recursion by using cfzip:
Here is an implementation of directoryCopy (minus the "overwrite" argument), using cfzip:
<cfargument name="source" required="true" type="string">
<cfargument name="destination" required="true" type="string">
<cfset var uid = CreateUUID()>
<cfdirectory action="create" directory="#arguments.destination#">
<cffile action="delete" file="#GetTempDirectory()##uid#.zip">
Now that I have done this, I can't think of any advantage this has over Joe's function, but it was a fun experiment.
Here are some brief speed tests in response to Nate's query:
|Test||subfolders||files||size||recursive cffile (milliseconds)||cfzip (milliseconds)|