<cfset Variables.TopMostDirectory = GetDirectoryFromPath(GetTemplatePath())>
<cfparam name="URL.Directory" default="#Variables.TopMostDirectory#">
<cfparam name="URL.ParentDirectory" default="">
<cfset Variables.IsTopMostDirectory = (URL.Directory is Variables.TopMostDirectory)>
<!--- Get the contents of the current directory --->
<cfdirectory directory="#URL.Directory#" action="list" name="qDir">
<!--- Identify the current directory --->
<cfoutput>
Directory: #URL.Directory#<p>
</cfoutput>
<!---
Display the contents of the current directory.
For files, display the file name.
For subdirectories, offer a hyperlink to display the subdirectory's contents.
--->
<cfoutput query="qDir">
<cfif Type is "Dir">
<cfset Variables.SubDirectory = URL.Directory & Name>
<cfset Variables.hlink = CGI.SCRIPT_NAME & "?Directory=" & Variables.SubDirectory>
<cfif Name is not Variables.TopMostDirectory>
<cfset Variables.hlink = Variables.hlink & "&ParentDirectory=" & URL.Directory>
</cfif>
<a href="#Variables.hlink#">#Name#</a><br>
<cfelse>
#Name#<br>
</cfif>
</cfoutput>
<p>
<!--- Offer a link to the parent directory (unless there is none) --->
<cfif not Variables.IsTopMostDirectory>
<cfset Variables.ParentDirectoryLink = CGI.SCRIPT_NAME & "?Directory=" & URL.ParentDirectory>
<cfoutput>
<a href="#Variables.ParentDirectoryLink#">Parent Directory</a>
</cfoutput><p>
</cfif>
David Shadovitz, Sr. S/W Engineer
Team Macromedia Volunteer for ColdFusion
Since each page is based on a template, I'll put the code in the template so that each page will have a recursive breadcrumb trail.
Basically, if a content contributor creates a directory beneath the home directory of their site section, all the other pages in the section will need to accomodate that change. The GetDirectoryFromPath thing will let me set it and forget it because new directories will automatically be listed by the tag.
I just can't figure out how to limit cfdirectory to display only directories, and I can't figure out how to make the resulting list into links.
Stuck on stupid, I guess.
Thanks for the help.
- Michael
m.clark
I was looking at your reply to a users code and have actually used it myself. I just wonder if I could ask you something?
Your code I am using is as follows:
<cfset Variables.TopMostDirectory = GetDirectoryFromPath(GetTemplatePath())>
<cfset Variables.DirSep = Right(Variables.TopMostDirectory,1)>
<cfset Variables.TopMostDirectory = Left(Variables.TopMostDirectory,Len(Variables.TopMostDirectory)-1)>
<cfparam name="URL.Directory" default="#Variables.TopMostDirectory#">
<cfparam name="URL.ParentDirectory" default="">
<cfset Variables.IsTopMostDirectory = (URL.Directory is Variables.TopMostDirectory)>
<!--- Get the contents of the current directory --->
<cfdirectory directory="#URL.Directory#" action="list" name="qDir">
<!--- Identify the current directory --->
<cfoutput>
Directory: #URL.Directory#<p>
</cfoutput>
<!---
Display the contents of the current directory.
For files, offer a hyperlink to download the file.
For subdirectories, offer a hyperlink to browse the subdirectory's contents.
--->
<table>
<cfoutput query="qDir">
<tr>
<cfif Type is "Dir">
<cfset Variables.SubDirectory = URL.Directory & Variables.DirSep & Name>
<cfset Variables.hlink = CGI.SCRIPT_NAME & "?Directory=" & Variables.SubDirectory>
<cfif Name is not Variables.TopMostDirectory>
<cfset Variables.hlink = Variables.hlink & "&ParentDirectory=" & URL.Directory>
</cfif>
<td> </td>
<td>#ListLast(Variables.SubDirectory,Variables.DirSep)#</td>
<td><a href="#Variables.hlink#">Browse</a></td>
<cfelse>
<td> </td>
<td>#Name#</td>
<td><a href="download.cfm?file=#ExpandPath(Name)#">Download</a></td>
</cfif>
</tr>
</cfoutput>
</table>
<p>
<!--- Offer a link to the parent directory (unless there is none) --->
<cfif not Variables.IsTopMostDirectory>
<cfset Variables.ParentDirectoryLink = CGI.SCRIPT_NAME & "?Directory=" & URL.ParentDirectory & "&ParentDirectory=" & ListDeleteAt(URL.ParentDirectory,ListLen(URL.ParentDirectory,Variables.DirSep),Variables.DirSep)>
<cfoutput>
<a href="#Variables.ParentDirectoryLink#">Parent Directory</a>
</cfoutput><p>
</cfif>
This seems to work except that when I try to download files in directories the path displayed in the download.cfm address bar indicates that the url path to the file (to be downloaded) is the path simply to the directory where the dirlist.cfm file is.
For example:
http://127.0.0.1/ebbn/stats/dirlist.cfm?Directory=C:\Inetpub\wwwroot\ebbn\stats\2002-10\helpdesk&ParentDirectory=C:\Inetpub\wwwroot\ebbn\stats\2002-10
should be pointing to a file found at:
C:\Inetpub\wwwroot\ebbn\stats\2002-10\helpdesk\2002-10 bradford call list.pdf
It's as though the browsed directories after the base url (http://127.0.0.1/ebbn/stats/) are missing.
Other than this the code seems fine.
Can you help please David?
Regards
Carl
Carl Moreton
T: 0774 763 7448