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
LVL 16
Gurpreet Singh RandhawaWeb DeveloperAsked:
Who is Participating?
 
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
 
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
 
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
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.