Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Contributor ,
Jun 29, 2010 Jun 29, 2010

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

578
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 29, 2010 Jun 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jun 29, 2010 Jun 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 29, 2010 Jun 29, 2010
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources