#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    Buffalo, NY
    Posts
    156
    Rep Power
    12

    How do I know if a file is there?


    I am trying to check to see if a specific file in a directory is there before I allow the user to move on.

    I'm looking for a way to basically say,
    <cfif #file# exists>
    <img src="#file#">
    <cfelse>
    You need to upload the file.
    </cfif>

    I looked at the CFFILE and CFDIRECTORY tags, and they don't seem to have a way to check like this.

    I looked into the list feature of CFDirectory, but I thought there must be a better way than to retrieve the list of files, then look through the list to see if the file name is there.

    Thanks for the help.
    Forget Milk!
    Gotspy?

    www.gotspy.com
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Netherlands
    Posts
    99
    Rep Power
    11
    hopefully the following snippet helps you out:

    <!--- Absolute path + filname to the expected file --->
    <cfset myFile = "C:\bogus.txt">

    <cfif FileExists(myFile)>
    <cfoutput>#myFile#</cfoutput> EXISTS!!!
    <cfelse>
    <cfoutput>#myFile#</cfoutput> DOES NOT EXIST!!!
    </cfif>
    Last edited by DeepDown; December 17th, 2003 at 09:53 AM.
    ** Don't expect me to code your needs, but if I am able to help, I'm willing. Shout, grab and use the hand!
    ** Man can no more own the land we walk upon, as they can lay claim on the air that we breath
    ** DeepDown I'm addicted to structures.... ohw and music
    ** Almost forgot I had an account here [*o*]
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    Buffalo, NY
    Posts
    156
    Rep Power
    12
    Wow,
    Look at that! the FileExists function is right there on Page 206 of the Cold Fusion5 Language Refrence! How did I miss that!?!?

    Thanks! I feel pretty stupid now. I use that book almost every day, and don't remember ever seeing that function.

    THANKS!
    Forget Milk!
    Gotspy?

    www.gotspy.com

IMN logo majestic logo threadwatch logo seochat tools logo