Skip to main content
Inspiring
Aug 20, 2006 3:43 AM UTC
Answered

cfdirectory List

I want to display files that are in a folder on the site.
I have:
<cfdirectory action="LIST" directory="D:\websites\mysite.com\www\wrs\#url.id#\" name="myDirectory">
<cfdump var="#myDirectory.name#">
Nothing shows eventhough 2 files have been uploaded there.
I did the cfdump & it says:
[empty string]

Any insight?

    This topic is closed to new replies. Start a new post to keep the conversation going.
    539ECorrect answer
    Inspiring
    Aug 20, 2006 11:01 PM UTC
    Cool.

    quote:

    Originally posted by: Adam Gertz
    The fileArray variables posted different. The index portion of the array changed the font to italic. Make sure to add the index as the first dimension of the array. fileArray [index] [number].


    3 replies

    Participant
    Aug 20, 2006 4:10 AM UTC
    The fileArray variables posted different. The index portion of the array changed the font to italic. Make sure to add the index as the first dimension of the array. fileArray [index] [number].
    Translate
    539EAuthorCorrect answer
    Inspiring
    Aug 20, 2006 11:01 PM UTC
    Cool.

    quote:

    Originally posted by: Adam Gertz
    The fileArray variables posted different. The index portion of the array changed the font to italic. Make sure to add the index as the first dimension of the array. fileArray [index] [number].


    Translate
    Participant
    Aug 20, 2006 4:06 AM UTC
    Your code looks good. I would maybe set your directory into a variable above. Example:
    <cfset Directory = "D:\websites\mysite.com\www\wrs\" & URL.ID>
    Then use Directory in the cfdirectory tag.

    Here's a working example from my site. I wrote this a while ago, but it is still functional.

    <h4>Directory Contents</h4>
    1) Name, 2) Size 3) Last Modified 4) Attributes
    <br /><br />

    <cfset currentDirectory = GetDirectoryFromPath(GetTemplatePath()) & "Uploaded">
    <cfdirectory name="myDirectory" directory="#currentDirectory#" action="list" />

    <cfset fileArray = ArrayNew(2)>
    <cfset i = 1>
    <cfloop query="myDirectory">
    <cfif myDirectory.type IS "file">
    <cfset fileArray [1] = myDirectory.name>
    <cfset fileArray
    [2] = myDirectory.size>
    <cfset fileArray [3] = myDirectory.dateLastModified>
    <cfset fileArray
    [4] = myDirectory.attributes>
    <cfset i = i + 1>
    </cfif>
    </cfloop>

    <cfdump var="#fileArray#" />
    <br />


    Translate