Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using CFTREE w/ CFFILE and CFDIRECTORY 1

Status
Not open for further replies.

jwdcfdeveloper

Programmer
Mar 20, 2001
170
US
My mistake on the previous entry, it's actaully the cftree tag that creates windows-like directories. What I want to know is can I use cftree (along w/ cffile and cfdirectory to upload files to either another server or another directory on the same server? I am open to suggestions.


Thanks
 
Hopefully you're using CF MX... as it makes things a LOT easier if you can wrap things up into a recursive CFFUNCTION.

If so, something like the following will do it for you:
Code:
<CFFUNCTION name=&quot;getDirectoryData&quot;>
   <CFARGUMENT name=&quot;directory&quot; required=&quot;yes&quot;> 

   <!--- ensure the query is private by initializing it with VAR, since we'll most likely be recursing --->
   <CFSET var qryDirectoryData = QueryNew(&quot;ATTRIBUTES,DATELASTMODIFIED,MODE,NAME,SIZE,TYPE&quot;)>

   <CFDIRECTORY ACTION=&quot;LIST&quot; DIRECTORY=&quot;#directory#&quot; NAME=&quot;qryDirectoryData&quot; SORT=&quot;name&quot;>
   <CFLOOP QUERY=&quot;qryDirectoryData&quot;>
     <CFSET QueryAddRow(qryTreeData)>
     <CFSET QuerySetCell(qryTreeData,&quot;value&quot;,&quot;#directory##qryDirectoryData.name#/&quot;)>
     <CFSET QuerySetCell(qryTreeData,&quot;display&quot;,&quot;#qryDirectoryData.name#&quot;)>		
     <CFSET QuerySetCell(qryTreeData,&quot;parent&quot;,&quot;#directory#&quot;)>		
     <CFSET QuerySetCell(qryTreeData,&quot;type&quot;,&quot;#lCase(qryDirectoryData.Type)#&quot;)>		
     <CFIF CompareNoCase(qryDirectoryData.Type,&quot;dir&quot;) EQ 0>
        <CFSET getDirectoryData(&quot;#directory##qryDirectoryData.name#/&quot;)>
     </CFIF>
   </CFLOOP>	
   <CFRETURN true>
</CFFUNCTION>


<CFSET sRootDirectory = &quot;/full/directory/path/&quot;>
<!--- or  sRootDirectory = ExpandPath(&quot;.&quot;)  to start at the current directory --->

<!--- establish a global query --->
<CFSET qryTreeData = QueryNew(&quot;value,display,parent,type&quot;)>

<CFSET getDirectoryData(sRootDirectory)>

<CFIF qryTreeData.RecordCount GT 0>
   <CFFORM ACTION=&quot;somepage.cfm&quot; METHOD=&quot;POST&quot; ENABLECAB=&quot;Yes&quot;>

   <CFTREE NAME=&quot;fileTree&quot; LOOKANDFEEL=&quot;Windows&quot; BOLD=&quot;No&quot; ITALIC=&quot;No&quot; BORDER=&quot;Yes&quot; HSCROLL=&quot;Yes&quot; VSCROLL=&quot;Yes&quot; REQUIRED=&quot;No&quot; COMPLETEPATH=&quot;No&quot; APPENDKEY=&quot;Yes&quot; HIGHLIGHTHREF=&quot;Yes&quot;>
   <CFLOOP query=&quot;qryTreeData&quot;>
      <CFTREEITEM VALUE=&quot;#qryTreeData.value#&quot; DISPLAY=&quot;#qryTreeData.display#&quot; PARENT=&quot;#qryTreeData.parent#&quot; QUERYASROOT=&quot;No&quot; EXPAND=&quot;Yes&quot;>
   </CFLOOP>
   </CFTREE>
</CFFORM>
</CFIF>

If you're not using MX... then it's a bit more difficult. Since the only alternative to CFFUNCTION is a CFSCRIPT function, and you can't run CFDIRECTORY within CFSCRIPT, you probably wouldn't be able to set up a recursive function. It which case, you'd probably have to declare ahead of time how many levels deep you want to go, and hardcode the loops for that specific depth. Not very fun.



-Carl
 
Yes I am using MX, and thanks for the code. Now once I've created this form could I use cfftp to move marked files (say I use a checkbox) to another server, or even a staging area?
 
You should be able to, yes... well... maybe.

As far as I know, the CFTREE only allows for single selection... so the user wouldn't be able to choose multiple files. Also, while you could make a custom graphic that looked like a checkbox inside the tree control, it would not behave like a checkbox... you select nodes simply be highlighting them.

But when the form is submitted, the chosen file would be returned on the action page as
Code:
#control_name.node#
. So for the above code, you'd look at
Code:
#filetree.node#
... which, in this case, contains the full path... otherwise you could look at
Code:
#filetree.path#
.

But, if you want multiple-select and checkboxes, CFTREE isn't for you. You'd be better off building your own listing in CFML and calling it into an IFrame to give it the horizontal and vertical scrollbars.




-Carl
 
I don't have to have checkboxes. I've never used cftree/cftreeitem tags and was not sure of a means of selecting certain files. As far as the cfdirectory is concerned I think I saw something in &quot;<i>Mastering ColdFusion MX</i>&quot; that uses the cfdirectory tag to create a list of directories/files and uses a cfoutput tag with a query attribute to display the directory. Thanks dude for all of your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top