CFLib.org – Common Function Library Project

IsExtValid(path, extlist)

Last updated December 19, 2001

author

Gyrus

Version: 1 | Requires: CF5 | Library: FileSysLib

Description:
Takes a file path and a comma-separated list of three-letter extensions. Returns TRUE if there's a three-letter extension that matches one in the list, otherwise FALSE. Can be tweaked to accept 4-letter extensions.

Return Values:
Returns a boolean.

Example:

<cfset path1="d:\docs\letter.doc">
<cfset path2="c:\blah.exe">
<cfset path3="d:\images\pic.tiff">
<cfset path4="d:\images\macImage">

<cfoutput>
path1 (#path1#) valid? #YesNoFormat(IsExtValid(path1, "doc,txt,pdf"))#<br />
path2 (#path2#) valid? #YesNoFormat(IsExtValid(path2, "doc,txt,pdf"))#<br />
path3 (#path3#) valid? #YesNoFormat(IsExtValid(path3, "doc,txt,pdf"))#<br />
path4 (#path4#) valid? #YesNoFormat(IsExtValid(path4, "doc,txt,pdf"))#<br />
</cfoutput>

Parameters:

Name Description Required
path The file path. Yes
extlist The list of valid extensions. Yes

Full UDF Source:

/**
 * Checks for a valid file extension.
 * 
 * @param path      The file path. 
 * @param extlist      The list of valid extensions. 
 * @return Returns a boolean. 
 * @author Gyrus (gyrus23@hotmail.com) 
 * @version 1, December 19, 2001 
 */
function IsExtValid(path,extlist) {
    // Find the last dot
    var DotPos = Find(".", Reverse(path));
    // Grab the extension
    var ext = Right(path, 3);
        return (not ((DotPos NEQ 4) OR (NOT ListFindNoCase(extlist, ext))));
}

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