We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Making the Path usabale

Medium Priority
259 Views
Last Modified: 2012-05-11
I have the following Path

/mypage/scenario/project/domain/webroot/mypage/sample.cfm

i want to truncate the last sample.cfm to be removed,

Please guide
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2015

Commented:
Like this?

Without Trailing Slash
<cfoutput>#REReplace("/mypage/scenario/project/domain/webroot/mypage/sample.cfm","/[^/]$","")#</cfoutput>

Open in new window


With Trailing Slash
<cfoutput>#REReplace("/mypage/scenario/project/domain/webroot/mypage/sample.cfm","[^/]$","")#</cfoutput>

Open in new window

CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2015
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
CERTIFIED EXPERT

Commented:
kaufmed's solution is better but you can also do it this way since the path can be viewed as a list with a / delimiter

<cfset test = "/mypage/scenario/project/domain/webroot/mypage/sample.cfm">

<cfoutput>
      
      #replace(test,listlast(test,"/"),"")#

</cfoutput>
CERTIFIED EXPERT

Commented:
of course the easiest way is

<cfset test = "/mypage/scenario/project/domain/webroot/mypage/sample.cfm">
<cfoutput>
#GetDirectoryFromPath(test)#
</cfoutput>
Bhavesh ShahLead Analyst
CERTIFIED EXPERT
Top Expert 2010

Commented:
Hi,

Just an additional option =)


<cfset test = "/mypage/scenario/project/domain/webroot/mypage/sample.cfm">

<cfoutput>
     
      #GetToken(test,Len(GetToken)-1,"/")#

</cfoutput>
CERTIFIED EXPERT

Commented:
CERTIFIED EXPERT

Commented:

(no points)

I agree with SidFishes, no need to create any type of regular expression when ColdFusion has a simple built in function that does exactly what you want...

#GetDirectoryFromPath("/mypage/scenario/project/domain/webroot/mypage/sample.cfm")#
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.