How to use the ColdFusion FileExist () method correctly?

I don't use coldfusion at all, but I need to fix the code a bit. Basically I am trying to check and see if the file I downloaded exists, and if it exists, increment the variable by 1. Then repeat until I get a unique file name. For some reason, I cannot find the correct way to use FileExist (). Some forums suggest using it with len (), but this is from 2006, and when I do this, it always seems true. Also, when I look at http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7c66.html , it says it returns either Yes or No. I tried to check the result in various ways, but no luck.

This is part of the code I'm dealing with. The application.file path is just a variable in my application file in which the path () extension is stored.

<cffile action="upload" destination="#Application.filePath#ListingsGallery/" filefield="iconImage" nameconflict="makeunique">
<cfset iconPlace = #cffile.serverfile#>
<cfset myExt = listLast(iconPlace,".")>
<cfset i = 1 >
<cfset myVar = false>
<cfloop condition="myVar EQ false">

    <cfset newIconName = "iconPhoto" & i &"."& myExt>
    <cfset iconName = Application.filePath & "ListingsGallery/" & #newIconName#>
<cfoutput>#iconName#</cfoutput><br />//just checking to see if it is the correct path, it is.

    <cfif FileExists(iconName) EQ 'Yes'>
         <cfoutput>#myVar#</cfoutput> //checking the value, it never hits here.
    <cfelse>
             <cfoutput>#myVar#</cfoutput><br /> //checking the value, it always hits here.
    <cfset myVar = true>        
             <cfoutput>#myVar#</cfoutput> //Again check the value.
    </cfif>
<cfset i++>
</cfloop>                     
<cffile action="rename" source="#Application.filePath#ListingsGallery/#iconPlace#" destination="#Application.filePath#ListingsGallery/#newIconName#">

The absolute path on the unix server is something like: / var / www / website folder name / etc .... Correct? That absolute path to the server, coldfusion docs seem to indicate at least the absolute path to the microsoft server, so I assume this is what is needed.

Edit --------------------------- PS: I can only give one of you a loan, so I gave it to Kruger, since he came a minute earlier. lol ...

+5
source share
4 answers

, . - , . , - - - . #expandPath ('.') # :) .

, . FYI - "EQ" YES ". :

<Cfif FileExists(iconName)>...

condition="NOT myVar">

CF.

Exists() , . ?

+3

FileExists() . , :

<cfif fileExists(TheFile)>
  // do this
<cfelse>
  // do that
</cfif>
+5

, , OP , CF , . 0 - , "", , "", "" "".

+3

All Articles