Skip to main content
Participant
October 6, 2010
Question

Problem with cfloop

  • October 6, 2010
  • 1 reply
  • 885 views

Here is what I am trying to do:

I want list files in downloads folder. Downloads folder ahe further sub-folder. So what I want to do is, list files in each subfolder seperately.

Here is the code I am using to do this:

<td headers="update_id"><a href="xyz">#request_id#</a></td>
        <td headers="title">#title#</td>
        <td headers="date">#date_submitted#</td>
        <td headers="name">#fname# #lname#</td>
        <td headers="completed">#isCompleted#</td>
        <td headers="email">#email#</td>
        <cfif hasAttachements eq "Y">
            <td headers="Attachments">
            <cfset dir_name="xyz\downloads\">
            <cfset dir_name= dir_name & title & date_submitted & "\">
            <cfset original_link_name= "xyz/downloads/" & title & date_submitted & "\">
            <cfdirectory action="list" directory=#dir_name# name="dirList#title#">
            <cfloop query="dirList#title#">
                <cfset link_name = original_link_name & #name#>
                <cfif name neq "." OR name neq "..">
                <cfoutput><a href="#link_name#">#name# </a><br /></cfoutput>
                </cfif>
            </cfloop>
            </td>
        </cfif>
    </tr>

    This topic has been closed for replies.

    1 reply

    Community Expert
    October 6, 2010

    Use the RECURSE attribute of CFDIRECTORY to recurse through subdirectories, and use the DIRECTORY column in the results to show the directory path.

    Dave Watts, CTO, Fig Leaf Software

    http://www.figleaf.com/

    http://training.figleaf.com/

    Fig Leaf Software is a Veteran-Owned Small Business (VOSB) on

    GSA Schedule, and provides the highest caliber vendor-authorized

    instruction at our training centers, online, or onsite.

    Dave Watts, Eidolon LLC
    bandaa25Author
    Participant
    October 6, 2010

    Actually the problem is:

    Suppose 1st directory has xxx.txt and yyy.txt

    It outputs them properly.

    Suppose 2nd has vvv.txt

    Then in this case it outputs as vvv.txt and vvv.txt where as it should print only once.

    Suppose 3rd one has abc.txt then it prints same file 3 times.

    SO basically it prints files correctly just that it prints them number equal to folder that I have browsed.

    I think I need something to actually reset cfloop so that it start again from start.

    Does any one know??

    Inspiring
    October 6, 2010

    cfdirectory returns a query object.

    cfoutput, when used with a query attribute, has a group attribute available.  That might not even be necessary.  cfdump the query and see how often each file appears.