Select file with CFDIRECTORY

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"
    SORT="name ASC, size DESC"
Action ="list"
<CFTABLE QUERY="myDirectory">

<select NAME="GetKeyList">
     <CFLOOP index="i" FROM="1" TO="#ListLen(Name)#">
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
Who is Participating?
pinaldaveConnect With a Mentor Commented:
you should not use index.

You should do as follows:
 <cfloop query="mydirectory">
     </cfloop >

That will do the job.
RollinNowAuthor Commented:
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)#">
     </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

gdemariaConnect With a Mentor Commented:

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

 <select name="GetKeyList">
      <cfoutput query="mydirectory">
          <option value="">
 </select >
RollinNowAuthor Commented:
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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.