Skip to main content
July 8, 2008
Question

Looping over cfdirectory

  • July 8, 2008
  • 2 replies
  • 1999 views
Hello. I am having an issue with looping over cfdirectory. What I am trying to do here is grab the size of the files associated with the db. So where #current.Dir.Name# = #DB Column# update size etc.... What's happening is it is displaying the same id about 90 something times...Nice I know. Can anyone help?

<cfloop query="qLoadFile">
<cfoutput>
<cfdirectory directory="/test1/test2/test3/0/#qLoadFile.owner_id#" action="list" name="currentDir">
#qLoadFile.owner_id# <!--- This does display my ids correctly if I end the loop here but does not display anything in my table if I end the loop here and reopen it--->
</cfoutput>

<table border="1" bordercolor="#000000" >
<tr>
<td>File Name</td>
<td>File Size</td>
<td>Directory Location</td>
<td>File Type</td>
</tr>

<cfloop query="currentDir">

<tr>
<cfoutput>
<form name="updateSize" action=" http://myURL.com/test2.cfm" method="post">
<td><input type="text" name="name" value="#currentDir.Name#" /></td>
<td><input type="text" name="size" value="#currentDir.Size#" /></td>
<td>#right(currentDir.DIRECTORY, 2)#</td>
<td>#currentDir.Type#</td>

</cfoutput>
</tr>
</cfloop>
</cfloop>
</table> <br />
<input type="text" name="number_of_directories" value="<cfoutput>#valuelist(qLoadFile.owner_id)#</cfoutput>">
<input type="submit" name="submit" value="submit"/>
</form>
    This topic has been closed for replies.

    2 replies

    July 10, 2008
    I just put your query into a random page of mine, changed the query to reflect a local database and got this output (all formatted correctly though!)

    Since I dont have the directory setup that you have the directory structures are empty, however it seems to be looping through fine

    59 File Name File Size Directory Location File Type
    60 File Name File Size Directory Location File Type
    61 File Name File Size Directory Location File Type
    62 File Name File Size Directory Location File Type
    63 File Name File Size Directory Location File Type
    64 File Name File Size Directory Location File Type
    65 File Name File Size Directory Location File Type

    Is this what you are looking for?
    Inspiring
    July 8, 2008
    cfdirectory produces a query. Maybe a query of queries will help.
    July 8, 2008
    Dan-

    Can you provide an example of what you mean by that? I am a little confused.

    NR
    July 10, 2008
    Can anyone provide an example of how to do this? I can't use a Union query because I don't have the same number of records being returned.