Re: Creating a directory listing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi David

Some comments inline ...

On 02 Apr,2003 at 10:22 David McGregor wrote:

<snip>
> I'm trying to do this for a web site. I need to list the contents of 
> each directory on a site to perhaps 4 levels deep (only html files). 
> I've almost got a function going where it starts at the top level and 
> checks each file to see if IT is a directory and if so chdir() to that </snip>

<?php
define("START","/home/ronan/Projects");
define("BRK","&nbsp;&nbsp;&nbsp;&nbsp;");

function getDirFiles($dirPath,$depth=0) {

  if ($handle = opendir($dirPath)) {

    while (false !== ($file = readdir($handle))) {
      // Make sure we aren't using this dir or the dir above us
      if ($file != "." && $file != "..") {

	// Print $file, indented by depth*BRK
	echo str_repeat(BRK,$depth).trim($dirPath."/".$file)."<br>";

	if (is_dir($dirPath."/".$file)) {
	   // If $file is a directory recursively call the function to
	   // list the files for that directory
	   getDirFiles($dirPath."/".$file,($depth+1));
	}

      }

    }
  // Close the dir handle
  closedir($handle);
  }
}

getDirFiles(START);
?>

That will give you an indented directory tree listing from the START directory, using BRK to create the indents.  This has no directory limit and will simply work through the entire tree.

Is that what you're after ?

You could build in your search logic pretty easily I think, with an 
'if (preg_match()) {}' type structure.

This is a modified version of johnpipi at hotmail.com's code at 

http://www.php.net/manual/en/ref.dir.php

<snip>
> 
> Thanks for any assistance.
> 
> Dave
</snip>

-- 
Ronan
e: ronan@thelittledot.com
t: 01903 739 997
w: www.thelittledot.com

The Little Dot is a partnership of
Ronan Chilvers and Giles Webberley

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux