Skip to main content
gokul1242
Inspiring
Jun 20, 2013 10:00 AM UTC
Question

how to use list function in CF

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 is closed to new replies. Start a new post to keep the conversation going.

5 replies

Jun 20, 2013 12:40 PM UTC

<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>

Translate
Inspiring
Jun 20, 2013 1:02 PM UTC

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

--

Adam

Translate
Inspiring
Jun 20, 2013 10:06 AM UTC

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

Translate
gokul1242
gokul1242Author
Inspiring
Jun 20, 2013 10:12 AM UTC

I used it as

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

But i got the output as

2009 Master Calendar  (4

Translate
Inspiring
Jun 20, 2013 10:19 AM UTC

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

Translate