Experiencing Problem With ColdFusion's ExpandPath('/') Function
For some strange reason, I've been experiencing a (very weird) problem with the ColdFusion function ExpandPath('/'). I have several web sites on various ColdFusion servers in a shared-host environment. Under normal circumstances, ExpandPath('/') would return the base absolute path for the web site.
For example, if you try using ExpandPath('/') in the default ColdFusion installation, it would most likely return "C:\ColdFusion8\wwwroot\"
However if a site is set up in a multi-instance environment (versus the default installation), ExpandPath('/') should return something similar to: "D:\Inetpub\domainname\"
Where I'm confused is why ExpandPath('/') would return "C:\ColdFusion8\wwwroot\" in a shared-host environment. It just doesn't make sense. Stranger still is if I try ExpandPath('/index.cfm') the shared-host server actually returns the correct response of "D:\Inetpub\domainname\index.cfm"
Why do I care? Well, I would be surprised if I'm the only ColdFusion developer who uses ExpandPath('/') in their programming. I usually store this handy little function in a variable and call it out from time to time in various parts of my applications for those times when I need an "absolute, platform-appropriate path." There are many functions that require the absolute path including the drive, directory, etc.
For now, I've come up with a hack to address this but I would prefer to find out what the cause of the problem is.
Option 1, possibly the easiest to implement, but not as dynamic:
<cfset request.RootDirectory = "D:\Inetpub\domainname\" />
Option 2, easier to replicate throughout multiple sites without have to retype the actual path:
<cfscript>
request.RootDirectory = expandpath("/index.cfm");
x = listlen(request.RootDirectory, "\");
request.RootDirectory = listdeleteat(request.RootDirectory, x, "\");
request.RootDirectory = request.RootDirectory & "\";
</cfscript>
Obviously, none of these are as easy as what I would prefer to do:
<cfset request.RootDirectory = ExpandPath("/") />
Comments
@todd, i agree, but cannot confirm from the host.
@Joshua, just tried it and that works! thank you!
but I wish I knew for sure why this happens from time to time.
<cfset request.rootDirectory = expandPath(".") & "/" />
<cfset mappings = factory.runtimeService.getMappings()>
Now it's <cfset request.rootDirectory = expandPath("./") />
@todd, yeah, i got a big ol' "Permission denied for creating Java object" from my host. thanks though!
@Dave, thanks for the tip.
Well, what you suggested works, kinda. Problem is, it returns the path to where the template is located which _may not_ be the "root" So I guess I'm back to my original hack for now.
request.rootDirectory = GetDirectoryFromPath( GetCurrentTemplatePath() ) ;
One of my sites was working fine for months and suddenly broke yesterday for no reason with the IDENTICAL situation you had.