Thanks Steve,

That part I already have working fine, it returns the query perfectly, the
problem lies (which I may have forgot to mention) within recreating the
directory visually with HTML.

Taco Fleur

Tell me and I will forget
Show me and I will remember
Teach me and I will learn 


> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf 
> Of Steve Onnis
> Sent: Wednesday, 21 April 2004 11:32 PM
> To: CFAussie Mailing List
> Subject: [cfaussie] RE: Tree (driving me nuts)
> 
> 
> Taco
> 
> maybe you can use this.  i also have one based on the COM 
> fileScripting object
> 
> If you want to add all the stuff into the attributes of the 
> cfc tags go for it.
> 
> * dirTree.cfc
> =========================================
> <cfcomponent>
> 
>       <cffunction name="new">
>               <cfset this.dirQuery = 
> QueryNew("Directory,Level,ChildrenCount,ParentDirectory,Direct
> oryID,ParentID
> ,Name")>
>               <cfset this.rootFolderCount = 0>
>               <cfset this.rootFolderCounter = 0>
>       </cffunction>
> 
>       <cffunction name="setPath">
>               <cfset this.startPath = Arguments[1]>
>       </cffunction>
> 
>       <cffunction name="getParent" access="private">
>               <cfset pos = 
> ListFindNoCase(ValueList(this.DirQuery.Directory),Arguments[1])>
>               <cfset ParentID = Val(this.DirQuery.DirectoryID[pos])>
>               <cfreturn ParentID>
>       </cffunction>
> 
>       <cffunction name="getSubFolders" access="private">
>               <cfdirectory action="LIST" name="listDirectory" 
> directory="#Arguments[1]#">
> 
>               <cfquery dbtype="Query" name="thisSubFolders">
>                       SELECT  *
>                       FROM    listDirectory
>                       WHERE   Type = 'Dir'
>               </cfquery>
> 
>               <cfset thisFullPath = ArrayNew(1)>
>               <cfset thisParentFolder = ArrayNew(1)>
> 
>               <cfloop query="thisSubFolders">
>                       <cfset thisFullPath[CurrentRow] = 
> Arguments[1]& "\" & Name>
>                       <cfset thisParentFolder[CurrentRow] = 
> Arguments[1]>
>               </cfloop>
>               <cfset 
> QueryAddColumn(thisSubFolders,"fullPath",thisFullPath)>
>               <cfset 
> QueryAddColumn(thisSubFolders,"parentFolder",thisParentFolder)>
>               <cfif this.rootFolderCount EQ 0>
>                       <cfset this.rootFolderCount = 
> thisSubFolders.RecordCount>
>               </cfif>
>               <cfreturn thisSubFolders>
> 
>       </cffunction>
> 
>       <cffunction name="displayFolders" access="private">
>               <cfset thisQuery = Arguments.CurrentFolder>
>               <cfset Level = Arguments.Level>
>               <cfloop query="thisQuery">
>                       <cfscript>
>                       if (NOT 
> isDefined("this.IDCounter")){this.IDCounter = 1;}
>                               this.IDCounter = this.IDCounter + 1;
>                               QueryAddRow(this.DirQuery);
>                               
> QuerySetCell(this.DirQuery,"DirectoryID",this.IDCounter);
> 
> QuerySetCell(this.DirQuery,"Directory",Replace(LCASE(fullPath)
> ,"\\","\","ALL
> "));
>                               
> QuerySetCell(this.DirQuery,"Level",Level);
>                               
> QuerySetCell(this.DirQuery,"ChildrenCount",0);
>                               QuerySetCell(this.DirQuery,"Name",Name);
>                               thisParentFolder = ParentFolder;
> 
> QuerySetCell(this.DirQuery,"ParentDirectory",Replace(LCase(par
> entFolder),"\\
> ","\","ALL"));
>                               
> getParent(Replace(LCase(parentFolder),"\\","\","ALL"));
>                               
> QuerySetCell(this.DirQuery,"ParentID",ParentID);
>                               getSubFolders(this.Directory= fullPath);
> 
>                               
> QuerySetCell(this.DirQuery,"ChildrenCount",thisSubFolders.Reco
> rdCount);
>                               Level = Level + 1;
>                               
> displayFolders(CurrentFolder=thisSubFolders,Level=level);
>                               Level = Level - 1;
>                       </cfscript>
>               </cfloop>
>       </cffunction>
> 
>       <cffunction name="getTree" access="public">
>               <cfset thisSubFolders = getSubFolders(this.startPath)>
>               <cfset 
> displayFolders(CurrentFolder=thisSubFolders,level=1)>
>               <cfreturn this.dirQuery>
>       </cffunction>
> 
> 
> </cfcomponent> 
> ============================================================
> 
> call it like this
> 
> <cfscript>
>       directoryTree = createObject("COMPONENT","dirTree");
>       directoryTree.new();
>       directoryTree.setPath("c:\");
>       dirResult = directoryTree.getTree();
> </cfscript>
> 
> this will return a query with the following columns.  if you 
> need to add columns i guess you can do so aswell
> 
> Directory             = the full path of the current directory
> Level                 = the leve in the tree this node is
> ChildrenCount = how many directories this directory has under it
> ParentDirectory       = The full path of the parent directory
> DirectoryID           = an index for the return query
> ParentID              = a parentid based on the "directoryid" 
> index column
> Name                  = just the name of the directory
> 
> Have fun
> 
> 
> Regards
> Steve Onnis
> Domain Concept Designs
> 
> 
> ---
> You are currently subscribed to cfaussie as: 
> [EMAIL PROTECTED] To unsubscribe send a blank email to 
> [EMAIL PROTECTED]
> 
> MXDU2004 + Macromedia DevCon AsiaPac + Sydney, Australia 
http://www.mxdu.com/ + 24-25 February, 2004


---
You are currently subscribed to cfaussie as: [EMAIL PROTECTED]
To unsubscribe send a blank email to [EMAIL PROTECTED]

MXDU2004 + Macromedia DevCon AsiaPac + Sydney, Australia
http://www.mxdu.com/ + 24-25 February, 2004

Reply via email to