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,DirectoryID,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(parentFolder),"\\
","\","ALL"));
getParent(Replace(LCase(parentFolder),"\\","\","ALL"));
QuerySetCell(this.DirQuery,"ParentID",ParentID);
getSubFolders(this.Directory= fullPath);
QuerySetCell(this.DirQuery,"ChildrenCount",thisSubFolders.RecordCount);
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