Solved

Select file with CFDIRECTORY

Posted on 2006-11-11
5
215 Views
Last Modified: 2013-12-24
I want to select a text file from list of files in a directory and use that file name for a variable.

My resultant selection box is either empty or I get an error trying to use a variable.  I guess I don't know how to set the variable name for the cfoop code so that the list displays or I don't know how to use cfdirectory, or both, or I need to take up Needle-point instead.


<CFDIRECTORY DIRECTORY="c:\server\default\keywords"
    NAME="myDirectory"
    SORT="name ASC, size DESC"
Action ="list"
filter="*.txt">
<CFTABLE QUERY="myDirectory">
    <CFCOL HEADER="NAME:"
            TEXT="#Name#">
    <CFCOL HEADER="SIZE:"
            TEXT="#Size#">
</CFTABLE>

   
<select NAME="GetKeyList">
     <CFLOOP index="i" FROM="1" TO="#ListLen(Name)#">
          <option><cfoutput>#listgetat(Name,i)#</cfoutput></option>
     </CFLOOP>
</SELECT>
How can I display a list of files in the directory, so I can then select one from the list to create a variable using the filename of the text file selected?

 -   Georgia
0
Comment
Question by:RollinNow
  • 2
  • 2
5 Comments
 
LVL 21

Expert Comment

by:pinaldave
ID: 17923362
<cfoutput>#mydirectory.name#</cfoutput>
0
 

Author Comment

by:RollinNow
ID: 17923507
Thanks. That's closer to working but my index TO is wrong. What do I use for the:

 FROM="1" TO="#ListLen(unknown)#">

Here's the loop:

<select name="GetKeyList">
     <cfloop index="i" FROM="1" TO="#ListLen(unknown)#">
          <option><cfoutput>#mydirectory.name#</cfoutput></option>
     </cfloop >
</select >

I don't need cfdirectory to list the names, just offer them in my selection drop-down list so I can select. As it is now, only one filename is avaiable, so what do I use for the unknown in <cfloop index="i" FROM="1" TO="#ListLen(unknown)#">

 - Georgia

0
 
LVL 21

Accepted Solution

by:
pinaldave earned 300 total points
ID: 17923578
Hello,
you should not use index.

You should do as follows:
 <cfloop query="mydirectory">
          <option><cfoutput>#mydirectory.name#</cfoutput></option>
     </cfloop >

That will do the job.
Regards,
---Pinal
0
 
LVL 39

Assisted Solution

by:gdemaria
gdemaria earned 200 total points
ID: 17923966

 Aren't you guys are forgetting the value parameter in option?


 <select name="GetKeyList">
      <cfoutput query="mydirectory">
          <option value="#mydirectory.name#"> #mydirectory.name#
     </cfoutput>
 </select >
0
 

Author Comment

by:RollinNow
ID: 17924070
Thanks pinaldave for the fix, and thanks so much to gdemaria for reminding me of SELECT. I was wondering why the form was blank!  You've got a share for your help.

  Thanks to both of you,

  - Georgia


0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now