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))));
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson