Skip to main content
gokul1242
Inspiring
June 20, 2013
Question

how to use list function in CF

  • June 20, 2013
  • 2 replies
  • 880 views

I have a file name as below :

2009 Master Calendar  (4.2.09).xls

Now how to use list funtions ie.listfirst or listlast to display the file name alone without the file ext.

ie,.2009 Master Calendar  (4.2.09)


This topic has been closed for replies.

2 replies

June 20, 2013

<cfset a = "2009 Master Calendar  (4.2.09).xls">

<cfset b = len(listlast(a,'.'))>

<cfset c = left(a,len(a) - b - 1)>

<cfoutput>#c#</cfoutput>

Inspiring
June 20, 2013

That's a lot more work that it needs to be. One can use listDeleteAt() to drop the last item from the list.

--

Adam

Inspiring
June 20, 2013

Are the docs somehow unclear?  You did read the docs, right?

http://help.adobe.com/en_US/ColdFusion/10.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7b62.html

What did you try, and in what way did it not work?

--

Adam

gokul1242
gokul1242Author
Inspiring
June 20, 2013

I used it as

<cfset filename=listfirst(#dirsOnly.Name#,'.')>

But i got the output as

2009 Master Calendar  (4

Inspiring
June 20, 2013

But you can see why that's happening, right? That *is* the first element of a dot-separated list, innit? So what you probably need to do is to revise your thinking slightly, and approach it from "how do I get rid of the last element of a list" (the file extension is the last element of a dot-delimited list.

How do you delete stuff from a list?

--

Adam