ODBiC Discussion Board


Recusing directories as an unordered list

by David Richardson, September 18, 2007 10:34

I'm trying to build an application part of which involves recursing through directories from a certain point. I've developed a function to do this (which I'll post below).

I'm sure this isn't the most elegant way to do it, but it's my first function. The main problem I'm having is empty <ul></ul> which really messes up the formating of the list.

I tried looking in the bonus files which I recalled did something similar, but I noticed that they only allow you to click on links to go to the next page. While that would work, I want to make this into a true directory treeview, mainly for speed.

Any ideas?

<!--DEFAULT topdirectory=mydirectory, filetype="*.*", selectedfile=""-->
<!--SET rootdirectory="d:\inetpub\wwwroot\"$topdirectory$-->

<% FUNCTION recurse (currentdirectory, is_subdirectory) %> <!--SET filerow=0--> <!--IF $is_subdirectory$--><ul><!--ENDIF--> <% EACHFILE $currentdirectory$ %> <% IF $file_is_dir$ %> <li><img src="images/folder.gif" />$file_name$ <% SET subdirectory=$rootdirectory$"\"$file_name$ %>

$recurse($subdirectory$"\"$filetype$, 1)

</li> <% ELSE %> <!--SET filerow=$filerow$+1--> <!--IF $filerow$=0--> <li>Empty</li> <!--ELSE IF $filerow$=1--> <li><a href="#">View files</a></li> <!--ENDIF--> <% ENDIF %>

<% ENDFILE %> <!--IF $is_subdirectory$--></ul><!--ENDIF--> <% RETURN %>

<ul class="dir" id="tree"> <li><strong>$topdirectory$</strong></li> $recurse($rootdirectory$"\"$filetype$, 0) </ul>



Replies:


Post Your Reply:

Name   
E-mail  optional
Topic  
Message:

HTTP Link: 
Link text: 

          


Copyright ©1997-2003, Roger Harris. All rights reserved.