Skip to main content
Inspiring
August 8, 2012
Question

How to get CF to read file names from a folder and display?

  • August 8, 2012
  • 3 replies
  • 1325 views

I have a folder with images and I'd like to have the image names displayed in a table, next to a corresponding customer number (which is pulled from a database) or if no image exists, then a noimage.jpg would disply as default. Can I do this in ColdFusion without having to reference image names from a database, etc.? For now, the images are just sitting in a folder. If so what code would I need to use? Thanks.

    This topic has been closed for replies.

    3 replies

    Inspiring
    August 8, 2012

    As others have mentioned, cfdirectory will provide you with the file names.  You can query your db for other stuff and put it all together with Query of Queries.

    Some of the details might be tricky.  Good luck and post back if you have difficulty.

    btvbillbAuthor
    Inspiring
    August 8, 2012

    Thanks everybody. I got it to work. Here is my code in case someone else needs help:

      <td>#CustomerName#</td>
      <td>#CustomerNumber#</td>
      <td><cfif FileExists("\\ncc1701-01\web\Sales\Information\images\#CustomerNumber#.png")>
            YES
        <cfelse>
            NO
        </cfif></td>
    Inspiring
    August 8, 2012

    Are you looking for something more than what CFDIRECTORY does?

    -reed

    WolfShade
    Legend
    August 8, 2012

    I was just going to suggest the same thing.  CFDIRECTORY (if it is turned on in CFAdmin) would be perfect. 

    ^_^

    WolfShade
    Legend
    August 8, 2012

    If the image names are not in the database, how would the image be associated with the customer?  Is the image filename the customer name or id?

    ^_^

    btvbillbAuthor
    Inspiring
    August 8, 2012

    Yes, its based on the customer number, ie.

    <td width="74%" align="left" valign="top"><img src="../RepInformation/images/#CustomerNumber#.png" onerror="this.src='../RepInformation/images/noImage.gif';"></td>