Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ColdFusion / General CF Topics / July 2008



Tip: Looking for answers? Try searching our database.

Listing Files and Directories

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Vidikron - 30 Jul 2008 17:39 GMT
On our internal web page we have some links to various areas like Office Forms,
Safety, etc... The supervisors that maintain these documents have access to
shares that allow them add, remove, and update the files as needed.  Since the
content in each changes fairly often we're currently using CFDIRECTORY with the
LIST action to display the contents to the users on the web page.

Some of the areas now contain quite a few documents and the supervisors would
like to be able to group their documents in subdirectories.  I know I can I can
use RECURSE="yes" to have the web page list the contents of these folders, but
the supervisors would like the end users to see the subdirectories as well so
things are less confusing and cluttered on both ends.  

So is there any way in CF to set up these pages so that subdirectories can can
be navigated and the documents selected?  If possible, I'd like something that
can handle this dynamically so that I don't have to constantly change the code
every time a supervisor decides to add/remove a directory.

We're currently running CF8 Standard.

Thanks!
Ian Skinner - 30 Jul 2008 17:59 GMT
> On our internal web page we have some links to various areas like Office Forms,
> Safety, etc... The supervisors that maintain these documents have access to
[quoted text clipped - 16 lines]
>
>  Thanks!

Pretty much what you got should do it.  The simplest change would be to
output entire directory structure on your current page, just nesting the
files and directories.

I would just create a looping output that uses the fields of the record
set to output the directories and the files with-in them probably as a
nested set of <ul> unordered lists.

If you want to break up this user interface into distinct units which
only list the contents of a current directory then just do the output as
you have it without using recursion.  But make the sub-directory
listings links that when clicked repopulate the current page listing the
contents of the selected directory.

Neither should take a great deal of rework to your current interface.
Vidikron - 30 Jul 2008 18:29 GMT
Could you give me a rough example?  I didn't write the current page and the
person that did is no longer here.   Here's the code that thepage is currently
using.

The "target" variable is being passed in the URL.  It's just the top level
directory where the listing of the files begins.  "Morpheus" is our internal
web server.

<cfif target NEQ "">
    <cfdirectory action="list" filter="*.*" recurse="no"
directory="#GetDirectoryFromPath(GetTemplatePath())#/#target#" sort="name ASC,
size DESC" name="rstDirectory">
    <cfif rstDirectory.recordcount NEQ 0>
        <cfoutput>
            <table width="100%">
                <tr>
                    <td>
                        <cfset counter = 1>
                        <cfset counterBack = 1>
                        <cfloop query="rstDirectory">

                            <cfif counter EQ 1>
                                <table align="left" <cfif style_page EQ
"3col_leftNav">width="50%"</cfif>>
                            </cfif>

                            <cfif counter EQ Ceiling(rstDirectory.recordcount / 2) + 1>
                                <cfif style_page EQ "3col_leftNav">
                                    </table>
                                    <table align="right" width="50%">
                                </cfif>
                                <cfset counterBack = 2>
                            </cfif>

                            <cfif counter EQ rstDirectory.recordcount + 1>
                                </table>
                            </cfif>

                            <tr>
                                <td class="TableText" bgcolor="###Iif(counterBack MOD 2 EQ 0,
DE('D5EAE9'), DE('FFFFFF'))#">
                                    <a href="http://morpheus/mi/#target#/#rstDirectory.name#" title="File
Date: #DateFormat(rstDirectory.dateLastModified, 'dddd, mmm dd,
yyyy')#"><strong>#rstDirectory.name#</strong></a>
                                </td>
                            </tr>
                        <cfset counter = counter + 1>
                        <cfset counterBack = counterBack + 1>
                    </cfloop>
                </td>
            </tr>
        </table>
        </cfoutput>
        <cfelse>
        There are no files to display.
    </cfif>
    <cfelse>
    <cflocation addtoken="no" url="http://morpheus/">
</cfif>
Ian Skinner - 30 Jul 2008 21:14 GMT
<cfparam name="url.dir"
default="#rereplace(getDirectoryFromPath(getCurrentTemplatePath()),'\\$','','ONE')#">

<cfdirectory action="list" name="allDir" directory="#url.dir#"
recurse="no" sort="ASC">

<cfoutput>#url.dir#</cfoutput>
<ul>
<cfoutput query="allDir">
    <cfswitch expression="#allDir.type#">
        <cfcase value="FILE">
            <li>FILE: #allDir.name#</li>
        </cfcase>
        <cfcase value="DIR">
            <li>DIR: #url.dir#\#allDir.name# <a
href="directoryFun.cfm?dir=#url.dir#\#allDir.name#">View</a></li>
        </cfcase>
    </cfswitch>
</cfoutput>

A simple directory display creating links to sub-directories.

A leave it to you to flesh out with your desire user interface and back
links to parent directories.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.