CFLib.org – Common Function Library Project

directoryCopy(source, destination [, ignore] [, nameConflict])

Last updated April 26, 2011

Version: 3 | Requires: ColdFusion MX | Library: FileSysLib

 
Rated 17 time(s). Average Rating: 4.5

Description:
Deep copies a directory, copying all children. Nameconflict parameter allows you to specific any valid nameconflict attribute for the cffile action="copy" tag (skip / overwrite / makeunique / etc.).

Return Values:
Returns nothing.

Example:

view plain print about
<cfset directoryCopy("c:\inetpub\wwwroot""c:\backups\wwwroot") />

Parameters:

Name Description Required
source Source directory. Yes
destination Destination directory. Yes
ignore List of folders, files to ignore. Defaults to nothing. No
nameConflict What to do when a conflict occurs (skip, overwrite, makeunique). Defaults to overwrite. No

Full UDF Source:

view plain print about
<!---
 Copies a directory.
 v3 mod by Anthony Petruzzi
 
 @param source      Source directory. (Required)
 @param destination      Destination directory. (Required)
 @param ignore      List of folders, files to ignore. Defaults to nothing. (Optional)
 @param nameConflict      What to do when a conflict occurs (skip, overwrite, makeunique). Defaults to overwrite. (Optional)
 @return Returns nothing. 
 @author Joe Rinehart (joe.rinehart@gmail.com) 
 @version 3, April 26, 2011 
--->

<cffunction name="directoryCopy" output="true">
    <cfargument name="source" required="true" type="string">
    <cfargument name="destination" required="true" type="string">
    <cfargument name="ignore" required="false" type="string" default="">
    <cfargument name="nameconflict" required="true" default="overwrite">

    <cfset var contents = "" />
    
    <cfif not(directoryExists(arguments.destination))>
        <cfdirectory action="create" directory="#arguments.destination#">
    </cfif>
    
    <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, "'")#)
        </cfquery>
    </cfif>
    
    <cfloop query="contents">
        <cfif contents.type eq "file">
            <cffile action="copy" source="#arguments.source#/#name#" destination="#arguments.destination#/#name#" nameconflict="#arguments.nameConflict#">
        <cfelseif contents.type eq "dir">
            <cfset directoryCopy(arguments.source & "/" & name, arguments.destination & "/" &  name) />

        </cfif>
    </cfloop>
</cffunction>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Tayo Akinmade Tayo Akinmade added
arrayTrim
4 day(s) ago

Will Belden Will Belden added
longTime
9 day(s) ago

James Sleeman James Sleeman added
quickSort
19 day(s) ago

Ben Forta Ben Forta added
GetHostAddress
22 day(s) ago

Top Rated

Darwan Leonardo Sitepu EksporSQLData
Rated 5.0, 16 time(s)

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 13 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson