IsExtValid(path, extlist)
Last updated December 19, 2001
Version: 1 | Requires: ColdFusion 5 | 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 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:
<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>
Search CFLib.org
Latest Additions
Dave Anderson added
iniToStruct
20 day(s) ago
Dave Anderson added
deDupeArray
20 day(s) ago
Richard added
dice
22 day(s) ago
Isaac Dealey added
getRelative
a while ago
Top Rated
backupDatabase
Rated 5.0, 22 time(s)
indentXml
Rated 5.0, 10 time(s)
generateSsccAsn
Rated 5.0, 4 time(s)
highlightAndCrop
Rated 5.0, 4 time(s)