Skip to main content
Inspiring
June 29, 2010
Question

FileExists() using web-root, not absolute path...

  • June 29, 2010
  • 1 reply
  • 656 views

Is there a way to use FileExists() with some sort of %webRoot% system variable, rather than me having to know the absolute path in advance?  For example if my app is running on one machine where the webroot is C:\ColdFusion9\webroot\ and on another machine where it's E:\Inetpub\webroot, is there a way for me to write a single piece of code that will check for the existence of "%webroot%\webSite\myFile.cfm"?

I guess what I'm really looking for here, is a system variable called something like %webRoot% in ColdFusion 9...  Does such an animal exist?

Thanks,

Laurence MacNeill

Mableton, Georgia, USA

    This topic has been closed for replies.

    1 reply

    Inspiring
    June 29, 2010

    Have a look at expandPath().

    Perhaps have a breeze through all the functions CF has, to give you a general idea of what it can / "can't" do:

    http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7ff8.html

    --

    Adam

    Inspiring
    June 29, 2010

    Let assume my function is contained in a .CFC file in C:\Inetpub\webroot\myapp\mycfcs

    So if I used the following statement:

    <cfif FileExists(ExpandPath(..\newcfcs\AttendeeInfo.CFC))>

    it would return true if the file C:\Inetpub\webroot\myapp\newcfcs\AttendeeInfo.CFC existed, yes?

    If that's the case, then great -- thanks!

    L.

    Inspiring
    June 29, 2010

    You can probably answer your own question by just... trying it!

    Your syntax is slightly off, but other than that, yes.  The docs are not clear.  Where they say "an absolute path", it means "a string representing an absolute path", not just the path, unquoted.

    But it's always good to do this sort of testing yourself...

    --

    Adam