Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CFFILE Write- How to make Unique if there's a conflict?

Any idea why CFFILE Write does not support making it unique but CFFile Upload does?

I'm using CFFILE Write to handle a GetHttpRequestData, and being able to support making it unique would be very helpful. Any ideas?

like image 849
WozPoz Avatar asked Dec 03 '22 04:12

WozPoz


2 Answers

Well, it doesn't. You'll have to roll your own unique names by first checking if the file exists and if it does, then add on some additional character(s) and repeat check/add until you've found something unique.

Alternatively, you always prepend something that ought to be fairly unique (e.g. date-time-incremental number).

like image 179
Gert Grenander Avatar answered Dec 25 '22 07:12

Gert Grenander


try something like this

<cfscript>
    i = 1;
    myPath = 'D:\webroot\sap\returns\log';
    myFileName = orderNumber;
</cfscript>
<cfloop condition="fileExists('#myPath#\#myFileName#.xml')">
    <cfscript>
        myFileName = '#orderNumber#_#i#';
        i += 1;
    </cfscript>
    <cfif i GT 100><cfbreak /></cfif>
</cfloop>

<cffile action="write" file="#myPath#\#myFileName#.xml" output="#xmlString#"  />
like image 38
Rob D. Avatar answered Dec 25 '22 06:12

Rob D.