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

current path

Community Beginner ,
Oct 04, 2009 Oct 04, 2009

Copy link to clipboard

Copied

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!

TOPICS
Advanced techniques

Views

535

Translate

Translate

Report

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

correct answers 1 Correct answer

Explorer , Oct 04, 2009 Oct 04, 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

Votes

Translate

Translate
Explorer ,
Oct 04, 2009 Oct 04, 2009

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
Community Beginner ,
Oct 04, 2009 Oct 04, 2009

Copy link to clipboard

Copied

LATEST

<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

Votes

Translate

Translate

Report

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
Documentation