Have you tried putting a CFDUMP of LocalDirectoryList immediately following the CFDIRECTORY to see what the data looks like? That should give you a pointer as to what the .NAME element is actually referring to.
Thanks, Reed. Yes, I did that. The value of the Name element is the directory name, which is exactly what it should be. In any case, that's evident from what I said:
I get either "Variable backgrounds is undefined" (for 1 or 2) or "The specified key, backgrounds, does not exist in the structure" (for 3, 4 or 5) .
As it happens, the name of that directory is "backgrounds". So the value I'm looking for DOES EXIST in the structure "LocalDirectoryList". And the code IS FINDING IT. But it thinks its the NAME of a key, instead of the VALUE of the key.
<cfset myDirName = name>
You don't need the evaluate statement (in fact you probably shouldnt need to use that ever in this day and age). And inside of your query loop you may address all of your query fields without prefix.
When in doubt, dump out your query from cfdirectory.
insuractive, thank you!
So simple! Actually, I had seen programmers use query variables inside loops without the query name, but I thought it was just for brevity and that the query name added clarity in reviewing the code. It never occurred to me that there would be situations where having the query name, or not, would make a difference.
You saved the day!
But it thinks its the NAME of a key, instead of the VALUE of the key.
Because that what the code is instructing CF to do ;-)
<CFSET ThisLocalDirectory = StructFind(LocalDirectoryList, Name)>
If you want to search for the literal string "Name" it must be enclosed in quotes. Otherwise you are instructing CF to treat it as a variable and to pass its value (ie "backgrounds") into structFind(). The same thing with evaluate().
<CFIF IsDefined("LocalDirectoryList.RecordCount") AND LocalDirectoryList.RecordCount GT "0">
However as Michael pointed out, there is rarely a need for evaluate, and under normal circumstances no need for that IsDefined either. The query should always exist and the loop will only execute if the query contains one or more records. So the code could be reduced to this.
<CFSET ThisLocalDirectory = LocalDirectoryList.Name>
Note, there is technically no need to assign #LocalDirectoryList.Name# to another variable either. It can be used directly.