CFLib.org – Common Function Library Project

GetFileFilterCount(directory, filter)

Last updated January 04, 2012

author

James Moberg

Version: 1 | Requires: CF6 | Library: UtilityLib

Description:
Accepts a directory path & a file filter. Returns number of matching files.

Return Values:
Returns a number.

Example:

<cfset JPGFileCount = GetFileFilterCount("C:\images", "*.jpg")>
<cfset GIFFileCount = GetFileFilterCount("C:\images", "*.gif")>

Parameters:

Name Description Required
directory directory path Yes
filter filter Yes

Full UDF Source:

<!---
 Accepts a directory path &amp; a file filter.  Returns number of matching files.
 
 @param directory      directory path (Required)
 @param filter      filter (Required)
 @return Returns a number. 
 @author James Moberg (james@ssmedia.com) 
 @version 1, January 4, 2012 
--->
rsion 1, May 17, 2011
*/
<cffunction name="GetFileFilterCount" returntype="numeric" output="no">
    <cfargument name="directory" type="string" required="true" />
    <cfargument name="filter" type="string" required="true" />
    <cfset var theCount = 0 />
    <cfset var checkfiles = "">

    <cfif directoryExists(arguments.directory)>
        <cfdirectory action="LIST" directory="#arguments.directory#" name="CheckFiles" filter="#arguments.filter#" type="file" listinfo="name">
        <cfset theCount = CheckFiles.RecordCount />
    </cfif>
    <cfreturn theCount />
</cffunction>

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson