How about something like this?
<cffunction name="printDirs" output="false" returntype="string">
<cfargument name="currDir" type="string" required="true">
<cfargument name="depth" type="numeric" required="true">
<!--- The following vars need to have their own scope for
EACH itereation of the function...hence the "var" keyword --->
<cfset var qryDirectory = "">
<cfset var returnString = "">
<!--- Grab the files in the directory signified by the
"currDir" argument. --->
<cftry>
<cfdirectory
action = "">
directory = "#currDir#"
name = "tmpDirectory"
sort = "ASC">
<cfcatch type="any"></cfcatch>
</cftry>
<!--- filter out all files that are NOT of type "Dir"
and store them in our scoped variable "qryDirectory" --->
<cfquery dbtype="query" name="qryDirectory">
SELECT name
FROM tmpDirectory
WHERE type = 'Dir'
ORDER BY name
</cfquery>
<!--- Loop through the query and create the "returnString" which will
hold all our data --->
<cfloop query="qryDirectory">
<cfif Left(qryDirectory.name, 1) NEQ ".">
<!--- The following line uses the depth argument to pad the spaces in
front of the directory name --->
<cfloop index="i" from="1" to="#depth*5#" step="1">
<cfset returnString = returnString & " ">
</cfloop>
<cfset returnString = returnString & "<directory name=""" &
qryDirectory.name & """>" & Chr(13)&Chr(10)>
<!--- This is our recursive call. We're passing in the current directory
as the "parent" and incrementing the depth value --->
<cfset returnString = returnString & printDirs( currDir &
qryDirectory.name & "/", Val( depth + 1 ) )>
<cfquery dbtype="query" name="qryFiles">
SELECT name
FROM tmpDirectory
WHERE type = 'File'
ORDER BY name
</cfquery>
<cfloop query="qryFiles">
<cfloop index="i" from="1" to="#(depth+1)*5#" step="1">
<cfset returnString = returnString & " ">
</cfloop>
<cfset returnString = returnString & "<file name=""" & qryFiles.name &
""" size=""" & " " & """ />" & Chr(13)&Chr(10)>
</cfloop>
<!--- When it comes back, close the directory structure --->
<cfloop index="i" from="1" to="#depth*5#" step="1">
<cfset returnString = returnString & " ">
</cfloop>
<cfset returnString = returnString & "</directory>" & Chr(13)&Chr(10)>
<!--- This just gives me a nice line break between "root" level
directories. --->
</cfif>
</cfloop>
<cfreturn returnString>
</cffunction>
<cfset currentDirectory = GetDirectoryFromPath( GetCurrentTemplatePath() )>
<cfxml variable="objTabs">
<rootDirectory>
<cfoutput>#printDirs( currentDirectory, 0 )#</cfoutput>
</rootDirectory>
</cfxml>
<cffile action="" file="#GetDirectoryFromPath( GetCurrentTemplatePath()
)#dirStruct.xml" output="#toString( objTabs )#">
-----Original Message-----
From: Troy Simpson [mailto:[EMAIL PROTECTED]
Sent: Friday, April 23, 2004 12:25 PM
To: CF-Talk
Subject: XML and FileSystem
All,
I want to query a file system and represent it's Hierarchical Structure
in XML.
Anyone have any suggestions or know where I might find information for
something like this?
I am sure this has been done before.
Thanks,
Troy
--
Troy Simpson
Applications Analyst/Programmer, OCPDBA, MCSE, SCSA
North Carolina State University Libraries
Campus Box 7111 | Raleigh | North Carolina
ph.919.515.3855 | fax.919.513.3330
E-mail: [EMAIL PROTECTED]
_____
[Todays Threads]
[This Message]
[Subscription]
[Fast Unsubscribe]
[User Settings]
- XML and FileSystem Troy Simpson
- Refresh Page Frank Py
- RE: Refresh Page Tony Weeg
- Hagan, Ryan Mr (Contractor ACI)