Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CFDIRECTORY For Listing Dirs and Subdirs

35 views
Skip to first unread message

David

unread,
Nov 12, 2002, 3:29:56 AM11/12/02
to
Here's some code I had fun putting together.
<!---
Filename: DirList.cfm
Description: Display directory tree
Author: David Shadovitz
--->

<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>
&nbsp;&nbsp;<a href="#Variables.hlink#">#Name#</a><br>
<cfelse>
&nbsp;&nbsp;#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>
&nbsp;&nbsp;<a href="#Variables.ParentDirectoryLink#">Parent Directory</a>
</cfoutput><p>
</cfif>

David Shadovitz, Sr. S/W Engineer
Team Macromedia Volunteer for ColdFusion

thinman

unread,
Nov 13, 2002, 12:11:12 AM11/13/02
to
David,

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

Carlos

unread,
Mar 21, 2003, 11:12:36 AM3/21/03
to
David,

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>&nbsp;&nbsp;</td>
<td>#ListLast(Variables.SubDirectory,Variables.DirSep)#</td>
<td><a href="#Variables.hlink#">Browse</a></td>
<cfelse>
<td>&nbsp;&nbsp;</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>
&nbsp;&nbsp;<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

0 new messages