Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to split a String by last delimiter in ColdFusion

In CF9, I have a string like C:\Docs\472837\nyspflsys\Medical Report\XLSX_46.xlsx

I want to split it by last backward slash, so it should look like
array[1] = C:\Docs\472837\nyspflsys\Medical Report and
array[2] = XLSX_46.xlsx

How to do it in ColdFusion 9 ?

like image 946
Abhilash Shajan Avatar asked Dec 14 '22 19:12

Abhilash Shajan


1 Answers

You may want to consider using GetDirectoryFromPath and GetFileFromPath.

<cfset fullPath = "C:\Docs\472837\nyspflsys\Medical Report\XLSX_46.xlsx">

<cfset dirPath  = getDirectoryFromPath(fullPath)>    <!--- C:\Docs\472837\nyspflsys\Medical Report\ --->
<cfset dirPath  = reReplace(dirPath, "[\\/]$", "")>  <!--- C:\Docs\472837\nyspflsys\Medical Report  --->
<cfset fileName = getFileFromPath(fullPath)>         <!--- XLSX_46.xlsx                             --->
like image 110
Alex Avatar answered Jan 07 '23 17:01

Alex