collectFiles(extensions, destinationPath, sourcePath)
Last updated April 5, 2006
Version: 2 | Requires: ColdFusion MX | Library: FileSysLib
Description:
This UDF will scan (recurse) a given path for a given list of files by extension and then copy them to the path you specify.
Return Values:
Returns nothing.
Example:
<cfset source = ExpandPath("./") />
<cfset collectFiles("asp,htm,html", destination, source) />
Parameters:
| Name | Description | Required |
|---|---|---|
| extensions | List of extensions to copy. | Yes |
| destinationPath | Destination directory. | Yes |
| sourcePath | Source directory. | Yes |
Full UDF Source:
<!---
Scans a directory (or path) for files of a specified extension and then copies them to the path you specify.
v2 by Raymond Camden. I just cleaned up the var statements.
@param extensions List of extensions to copy. (Required)
@param destinationPath Destination directory. (Required)
@param sourcePath Source directory. (Required)
@return Returns nothing.
@author Steven Ross (steven.ross@zerium.com)
@version 2, April 7, 2006
--->
<cffunction name="collectFiles" access="public" hint="recurses through a directory and collects the file types you want then outputs to another directory" returnType="void">
<cfargument name="extensions" required="true" type="string" hint="The extensions you want to gather up csv (list) format ex:(asp,cfm,jsp) ">
<cfargument name="destinationPath" required="true" type="string" hint="absolute path to storage directory">
<cfargument name="sourcePath" required="true" type="string" hint="absolute path to source directory">
<cfset var root = arguments.sourcePath/>
<cfset var i = "">
<cfset var absPath = "">
<cfset var relativePath = "">
<cfset var writeTo = "">
<cfset var pathAndFile = "">
<cfif not directoryExists(arguments.sourcePath)>
<cfthrow message="Source Directory (#arguments.sourcePath#) not found" detail="You didn't pass in a valid source directory, check the path and try again.">
</cfif>
<cfloop list="#arguments.extensions#" index="i">
<cfdirectory name="getFiles" directory="#root#" recurse="true" filter="*.#i#">
<cfloop query="getFiles">
<cfset absPath = getFiles.directory & "/" />
<cfset relativePath = Replace(absPath, root, "", "all") />
<cfset writeTo = ARGUMENTS.destinationPath & "/" & relativePath>
<cfset pathAndFile = getFiles.directory & "/" & getFiles.name />
<cfif not directoryExists(writeTo)>
<cfdirectory action="create" directory="#writeTo#">
<cffile action="copy" source="#pathAndFile#" destination="#writeTo#">
<cfelse>
<cffile action="copy" source="#pathAndFile#" destination="#writeTo#">
</cfif>
</cfloop>
</cfloop>
</cffunction>
Search CFLib.org
Latest Additions
Raymond Compton added
structBlend
19 day(s) ago
Duncan added
IsZIPUK
19 day(s) ago
Todd Sharp added
getTagContentAll
25 day(s) ago
Gerald Guido added
ListReturnDuplicat...
1 month(s) ago
Gerald Guido added
ListReturnDuplicat...
1 month(s) ago