CFFILE Write - How to make it unique if there is a conflict?

Any idea why CFFILE Write doesn't support its uniqueness, but does CFFile Upload do?

I use CFFILE Write to handle GetHttpRequestData, and the ability to maintain its uniqueness will be very useful. Any ideas?

+3
source share
3 answers

Well, that is not so. You will have to collapse your own unique names, first checking to see if the file exists, and if it does, then add some extra characters and repeat the check / add until you find something unique.

, (, ).

+9

-

<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#"  />
+5

How to use CreateUUID () as a file name?

+4
source

Source: https://habr.com/ru/post/1756458/


All Articles