Solved

Select file with CFDIRECTORY

Posted on 2006-11-11
5
217 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…

830 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