the function works as evident by the <cfoutput>'s remarked with DEBUG
my script always errors out saying that "Variable NEWFILENAME is undefined."
its as if the cfreturn is not returning anything
anyone have an idea as to what's wrong?
<!--- folder contains dinner1.jpg, dinner11.jpg, and dinner12.jpg --->
<cfparam name="filepath" default="D:\uploadtest\">
<cffunction name="AutoIncrement" access="public" returntype="string">
<cfargument name="filename" type="string" required="yes" default=0>
<cfargument name="path" type="string" required="yes" default=0>
<cfargument name="step" type="numeric" required="no" default=1>
<!--- Split filename into name and extension --->
<cfset extension = listGetAt(filename, 2, '.')>
<cfset fileroot = listGetAt(filename, 1, '.')>
<!--- Conduct FileExists for fileroot + step, else increment by 1 and try again --->
<cfif FileExists("#path#/#fileroot##step#.#extension#")>
<!--- DEBUG ---> <cfoutput>#fileroot##step#.#extension# exists</cfoutput><br />
<cfset AutoIncrement(filename=filename,path=path,step=step+1)>
<cfelse>
<!--- DEBUG ---> <cfoutput>#fileroot##step#.#extension# does not exist</cfoutput>
<!--- filename is valid, return to the user --->
<cfset filenametest = fileroot & step & "." & extension>
<cfreturn filenametest>
</cfif>
</cffunction>
<cfset newFileName = AutoIncrement(filename="dinner1.jpg",path=filepath)>
<br /><cfoutput>#newFileName#</cfoutput>
This post has been edited by sjlsam: 29 October 2008 - 01:22 PM

New Topic/Question
Reply




MultiQuote




|