I've been trying to figure out why my array won't output.
I did a var dump on the array and it dumps it just fine but when I try to output it, it returns fatal error. In addition, I figured that maybe I had to probably loop over the array in order to access it, so I tried that too and managed to loop over the array by doing a var dump but when I output it, it breaks the page.
Here is my code that I attempted i've been trying for almost 3 hours now trying various things.
ColdFusion:
<cfset defaultDirectory = "C:\uploads\" />
<cfdirectory
directory="#defaultDirectory#"
action="list"
name="myList"
>
<!---Get Array of Directory Names --->
<cfquery dbtype="query" name="fileNames">
SELECT NAME
FROM myList
</cfquery>
<!---Create array --->
<cfset myArray=arraynew(1)>
<!---Populate array with directory query data "name" --->
<cfloop query="fileNames">
<cfset myArray[CurrentRow][1]=#defaultDirectory# & NAME & "\">
</cfloop
Up to this point, everything seemed to be going good. I dumped out the array variable and it outputted what I wanted. So I tried this and it returned a fatal error.
<cfoutput>
<cfif directoryExists("#myArray[1]#")>
it exists.
<cfelse>
Doesn't exists.
</cfif>
<cfoutput>
Here is the screenshot of the variable being dumped.
What I then figured was maybe I have to loop over the array in order to access it?
so I tried this.
<cfloop index="i" from="1" to="#arrayLen(myArray)#">
<cfdump var="#myArray[i]#"
</cfloop>
this managed to dump out all things from the array but when i try to output it, it returns a fatal error I'm not sure why. I looked up tutorials on how to dump the array and I'm not sure what I'm doing wrong? Any suggestions would be appreciated.
Here is a screenshot of the structure of myArray that was requested:
I did
<cfvar dump="#myArray#">


<cfdirectory>returns a query upon which you can perform array functions. At the very least, the filenames q of q looks redundant. - Dan Bracuk