|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Converting query to comma separated list
First question, though I suspect this might not be the best approach ...is it possible to turn a query (cfdirectory in this case) into a comma separated list?
The reason I ask is bcos currently I have a hardcoded list of folders in my action file, and I loop through and pull all the files from each. Like so... <cfloop index = "thisItem" list = "maps,districtPlans,mgmtPlans"> <cfdirectory name="getAllFiles" action="list" directory="#serverdir##thisItem#" sort="name ASC"> <cfquery dbtype="query" name="getAllFiles_#thisItem#"> SELECT * FROM getAllFiles </cfquery> </cfloop> and in the display page something like... <ol> <cfoutput query="getAllFiles_maps"> #replace(listFirst(name), "_", " ", "ALL")#<br /> </cfoutput> </ol> <ol> <cfoutput query="getAllFiles_mgmtPlans"> #replace(listFirst(name), "_", " ", "ALL")#<br /> </cfoutput> </ol> -------------------- This is all working fine...My question is two-part really. Instead of hardcoding the list, I can do another directory call like so... <cfdirectory name="getAllFolders" action="list" directory="#serverdir#" sort="name ASC"> which will give me all the folders that are in the above list (ie maps,districtPlans etc). So, how to get the query to a list so I don't need to hardcode? OR, is this the wrong approach and is it possible to use the getAllFolders query directly in some fashion? TIA Mark |
|
#2
|
|||
|
|||
|
Here's what seems to work....
<cfdirectory name="getAllFolders" action="list" directory="#serverdir#" sort="name ASC"> <cfloop query = "getAllFolders"> <cfdirectory name="getAllFiles" action="list" directory="#serverdir##name#" sort="name ASC"> <cfquery dbtype="query" name="getAllFiles_#name#"> SELECT * FROM getAllFiles </cfquery> </cfloop> adieu Mark |
|
#3
|
||||
|
||||
|
I think what you are doing is correct. that is the best way to pull out all the directory structure.
I have just changed your code a bit here. Code:
<cfdirectory
name="getAllFolders"
action="list"
directory="#serverdir#"
sort="name ASC">
<cfloop query = "getAllFolders">
<!--- process only directories and escape root . directories --->
<cfif type eq "Dir" and name neq "." AND name neq "..">
<strong><cfoutput>#name#</cfoutput></strong> :
<cfdirectory
name="getAllFiles"
action="list"
directory="#serverdir##name#"
sort="name ASC">
<!--- exclude dir name . and .. --->
<cfquery dbtype="query" name="qry_getAllFiles">
SELECT * FROM getAllFiles Where name not in ('.','..')
</cfquery>
<ol>
<cfoutput query="qry_getAllFiles">
#replace(listFirst(name), "_", " ", "ALL")#<br/>
</cfoutput>
</ol>
</cfif>
</cfloop>
__________________
SR - webshiju.com www.lizratechnologies.com "The fear of the LORD is the beginning of knowledge..." |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > Converting query to comma separated list |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|