Skip to main content
Inspiring
May 2, 2013
Answered

cfloop w/ FileExists, color coding presence or not

  • May 2, 2013
  • 1 reply
  • 772 views

Hello,

CF Version: 8

I have fifty(50) records returned with the query below. I want to loop through those

records to see if the associated file actually exists on the server. If the file does

exist then display the file name in green text if it does not then display in red.

My current code picks up that the first file does exist and sets the color to green

as well as all the rest of the document information. I know for a fact that some of

the documents are missing, so some of the documents names should be displaying

in red. The output is correctly displaying all the records, just not changing colors

respectfully to the presence of the file.

What am I doing wrong? Am I going about this all wrong?

 

<cfloop query="rsDocuments">

<cfoutput>

<div style="margin-bottom: 15px;">

#disp_title#<br />

<cfif FileExists(#FilePath#)>

<span style="color: ##093;">#doc_file#</span>

<cfelse>

<span style="color: ##F00;">#doc_file#</span>

</cfif>

</div>

</cfoutput>

</cfloop>

Thanks in advance for insight.

Leonard B

    This topic has been closed for replies.
    Correct answer bforta@adobe.com

    First thing I'd do is display #FilePath# as you loop, just to make sure it contains what you are expectign it to contain. Then you can see if there is a pattern to which are being found and which are not.

    --- Ben

    1 reply

    bforta@adobe.com
    Adobe Employee
    bforta@adobe.comCorrect answer
    Adobe Employee
    May 2, 2013

    First thing I'd do is display #FilePath# as you loop, just to make sure it contains what you are expectign it to contain. Then you can see if there is a pattern to which are being found and which are not.

    --- Ben

    Leonard_BAuthor
    Inspiring
    May 12, 2013

    Hello, Ben.

    Sorry for the slow response, work has been slamming me.

    Thanks for the response, was focusing on wrong area of the process. Did what you suggested and the issue became apparent. I was then able to correct and achieve the desired outcome

    Leonard B