One of the things that always get's me is the fact that in ColdFusion, the ExpandPath() method expands the path of the base path. I would say 95% of the time, this doesn't matter, but the other 5% of the time, I end putting stuff in the wrong directories. In my head, it just makes sense that ExpandPath() should expand the current template path since that is the one calling the code (just how the CFInclude template attribute works).
When I do need to expand the current path, not the base one, I just use the GetCurrentTemplatePath(). And, since expand path is meant to add to a directory, I get the directory from the returned path:
Launch code in new window » Download code as text file »
Assuming that we have the current directory structure:
sites
..test
....index.cfm
....sub
......test.cfm
and that our CGI.script_name points us to the page "index.cfm" but the code is being executed by the CFIncluded page, test.cfm, the first path would be:
D:\sites\test\
and the second path would be:
D:\sites\test\sub\
So anyway, just keep that in mind. We use CFIncludes so much in ColdFusion that I feel it easy to make this mistake.
Download Code Snippet ZIP File
Comments (2) | Post Comment | Ask Ben | Permalink | Other Searches | Print Page
Thanks Ben - your Blog has to be the most useful resource out there when it comes to CF Quirks - I remember reading this entry a couple of years back - first port of call when I needed to do this...
Posted by Dan Lancelot on Oct 20, 2008 at 6:27 AM
@Dan,
I am always happy to hear that I have provided some value - thanks.
Posted by Ben Nadel on Oct 22, 2008 at 7:30 AM