CFLib.org – Common Function Library Project

filterFilename(filename)

Last updated January 19, 2006

author

Jason Sheedy

Version: 1 | Requires: CF6 | Library: UtilityLib

Description:
This function will remove any reserved characters from a filename string and replace any spaces with underscores.

Return Values:
Returns a string.

Example:

<cfset newfilename = filterFilename(filename) />

<cfoutput>
#newfilename#
</cfoutput>

Parameters:

Name Description Required
filename Filename. Yes

Full UDF Source:

<!---
 This function will remove any reserved characters from a filename string and replace any spaces with underscores.
 
 @param filename 	 Filename. (Required)
 @return Returns a string. 
 @author Jason Sheedy (jason@jmpj.net) 
 @version 1, January 19, 2006 
--->
<cffunction name="filterFilename" access="public" returntype="string" output="false" hint="I remove any special characters from a filename and replace any spaces with underscores.">
	<cfargument name="filename" type="string" required="true" />
	<cfset var filenameRE = "[" & "'" & '"' & "##" & "/\\%&`@~!,:;=<>\+\*\?\[\]\^\$\(\)\{\}\|]" />
	<cfset var newfilename = reReplace(arguments.filename,filenameRE,"","all") />
	<cfset newfilename = replace(newfilename," ","_","all") />
	
	<cfreturn newfilename /> 
</cffunction>
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