CFLib.org – Common Function Library Project

IsExtValid(path, extlist)

Last updated December 19, 2001

Version: 1 | Requires: ColdFusion 5 | Library: FileSysLib

 
Rated 0 time(s). Average Rating: 0

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:

view plain print about
<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:

view plain print about
<cfscript>
/**
 * 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))));
}
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Dave Anderson Dave Anderson added
iniToStruct
20 day(s) ago

Dave Anderson Dave Anderson added
deDupeArray
20 day(s) ago

Richard Richard added
dice
22 day(s) ago

Isaac Dealey Isaac Dealey added
getRelative
a while ago

Top Rated

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

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Raymond Camden highlightAndCrop
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson