• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 249
  • Last Modified:

Making the Path usabale

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
0
Gurpreet Singh Randhawa
Asked:
Gurpreet Singh Randhawa
1 Solution
 
käµfm³d 👽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

0
 
käµfm³d 👽Commented:
Arrggh...  Correction:


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

0
 
SidFishesCommented:
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>
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
SidFishesCommented:
of course the easiest way is

<cfset test = "/mypage/scenario/project/domain/webroot/mypage/sample.cfm">
<cfoutput>
#GetDirectoryFromPath(test)#
</cfoutput>
0
 
Bhavesh ShahLead AnalysistCommented:
Hi,

Just an additional option =)


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

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

</cfoutput>
0
 
SidFishesCommented:
0
 
gdemariaCommented:

(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")#
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now