– Common Function Library Project

directoryCopy(source, destination[, ignore])

Last updated March 21, 2013


Joe Rinehart

Version: 3 | Requires: CF6 | Library: FileSysLib

Deep copies a directory, copying all children. Note that this UDF is redundant after CF9, as CF10 has a built-in function to perform this action.

Return Values:
Returns nothing.


<cfset directoryCopy("c:\inetpub\wwwroot", "c:\backups\wwwroot") />


Name Description Required
source Source directory. Yes
destination Destination directory. Yes
ignore List of folders, files to ignore. Defaults to nothing. No

Full UDF Source:

 Copies a directory.
 v1.0 by Joe Rinehart
 v2.0 mod by [author not noted]
 v3.1 mod by Anthony Petruzzi
 v3.2 mod by Adam Cameron under guidance of Justin Z (removing NAMECONFLICT argument which was never supported in file-copy operations)
 @param source      Source directory. (Required)
 @param destination      Destination directory. (Required)
 @param ignore      List of folders, files to ignore. Defaults to nothing. (Optional)
 @return Returns nothing. 
 @author Joe Rinehart ( 
 @version 3.2, March 21, 2013 
<cffunction name="directoryCopy" output="false" returntype="void">
    <cfargument name="source" required="true" type="string">
    <cfargument name="destination" required="true" type="string">
    <cfargument name="ignore" required="false" type="string" default="">

    <cfset var contents = "">
    <cfif not(directoryExists(arguments.destination))>
        <cfdirectory action="create" directory="#arguments.destination#">
    <cfdirectory action="list" directory="#arguments.source#" name="contents">

    <cfif len(arguments.ignore)>
        <cfquery dbtype="query" name="contents">
        select * from contents where name not in(#ListQualify(arguments.ignore, "'")#)
    <cfloop query="contents">
        <cfif contents.type eq "file">
            <cffile action="copy" source="#arguments.source#/#name#" destination="#arguments.destination#/#name#">
        <cfelseif contents.type eq "dir">
            <cfset directoryCopy(arguments.source & "/" & name, arguments.destination & "/" & name)>


Latest Additions

Raymond Camden added
November 04, 2017

Leigh added
May 11, 2016

Raymond Camden added
May 10, 2016

Kevin Cotton added
May 05, 2016

Raymond Camden added
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson