Skip to main content
Known Participant
October 4, 2009
Answered

current path

  • October 4, 2009
  • 1 reply
  • 669 views

I need an idiot-proof way of determining the current path of the template I’m working with.

If I have a path C:\ColdFusion8\wwwroot\mysite\folder\index.cfm: How do I isolate the thing that it only gives me “folder” and NOTHING else? I tried getDirectoryFromPath, but I get an “all-or nothing- type result.

Please, someone put it up in idiot-code what do I need to do to just get the value of the current folder I’m in and nothing else.

Please don’t tell me use “x” function – I’ve tried a few but I’m at wit’s end!

This topic has been closed for replies.
Correct answer Nathan_Mische

Here are two possible ways:

<cfset dir = listLast(getDirectoryFromPath(getCurrentTemplatePath()),"/") />


<cfset dir = listGetAt(getCurrentTemplatePath(),listLen(getCurrentTemplatePath(),"/")-1,"/")/>

You may need to change the list delimiter to "\" depending on your platform.

--Nathan

1 reply

Nathan_MischeCorrect answer
Inspiring
October 4, 2009

Here are two possible ways:

<cfset dir = listLast(getDirectoryFromPath(getCurrentTemplatePath()),"/") />


<cfset dir = listGetAt(getCurrentTemplatePath(),listLen(getCurrentTemplatePath(),"/")-1,"/")/>

You may need to change the list delimiter to "\" depending on your platform.

--Nathan

JellyheadAuthor
Known Participant
October 5, 2009

<cfset dir = listLast(getDirectoryFromPath(getCurrentTemplatePath()),"/") />

- does not work, gives me the same ol' same ol'

<cfset dir = listGetAt(getCurrentTemplatePath(),listLen(getCurrentTemplatePath(),"/")-1,"/") />

Works a treat!  This is what I was looking for - thank you, you are now the proud owner of a few beers next time you are in my hometown.

G