rique
rique

Reputation: 247

find last occurrence of `/` in file path in coldfusion

In Coldfusion, I tried to find the function to find the index value of last occurrence of / in file path so that file name after / is picked up. can any body suggest me the solution. I want to retrieve file name from a file path.

Upvotes: 4

Views: 4625

Answers (3)

Daryl B
Daryl B

Reputation: 1

Work great. change the code to use . to get the extension of a file for create a archive file name to back up old version.

Added the code listLast(form.Document_File_Nm, "."> to the below plus added the period back in to the filename.

<cfset ArchiveFileName = mid(form.Document_File_Nm,1,len(form.Document_File_Nm)-4) & '_' & trim(ATTUID) & '_' & DateFormat(now(),'YYYYMMDD') & TimeFormat(now(),'HHMMSS') & '.' & listLast(form.Document_File_Nm, ".")>

Upvotes: 0

coldfusiondevshop
coldfusiondevshop

Reputation: 683

Use GetFileFromPath(filepath). It returns the file name from a given path.

<cfset fileName = GetFileFromPath(filepath)>

Upvotes: 19

Adam Cameron
Adam Cameron

Reputation: 29870

You could either use listLast() to get the fragment of the string you want directly:

filePart = listLast(fullPath, "/\");

Or you could simply use java.lang.String's lastIndexOf() method to approach it exactly the way you describe.

However I'd just use listLast().

Upvotes: 5

Related Questions