Re: directory help

From: Date: Mon, 17 Jul 2000 05:23:20 +0000
Subject: Re: directory help
Groups: php.general 
Request: Send a blank email to php-general+get-6867@lists.php.net to get a copy of this message
Addressed to: apocolypse@jam.rr.com php-general@lists.php.net ** Reply to note from Jay Hester <apocolypse@jam.rr.com> Sun, 16 Jul 2000 22:25:55 -0500 > > Hi, I need to recursivly traverse a directory path, anyone have any > ideas on how to do this? I've tried many things, but none have been > successful so far. Thanks! > What timing.... I just coded one of these. <? function GetDirectories( $Base, $Path, $Directory, $Spaces ) { echo $Spaces, $Directory, "<BR>\n"; $CurrDir = $Base . $Path; $D = opendir( $CurrDir ); while( $Dir = readdir( $D )) { # if ., .. or hidden, skip it if( ereg( "^\.", $Dir )) continue; $X = "$CurrDir/$Dir"; # if not a directory, skip it. # You could echo files here or something if( !is_dir( $X )) continue; GetDirectories($Base, "$Path$Dir/", $Dir, "$Spaces&nbsp;&nbsp;" ); } } GetDirectories( "/web/hosts/www.somedomain.com/pub/images", "/", "/", '' ); ?> GetDirectories( $Base, $Path, $Directory, $Spaces ); o Base: leading path that is not displayed. o Path: Pre-Parsed path info. Start with / to display contents of Base directory. o Directory: The current directory. This function prints the name of the current directory, then searches it for directories. o Spaces: The number of spaces to put at the front of the directory name. My current test data looks like this when this is run: / another deeper more wider more deeper more wider I actually have a bit more in my code that makes each entry links into the directory tree. I have stripped out much of the code, but there should be just enough to give you the directory you select and a list of all directories below it. If you want to see the files too, just attach your files code in place of the second continue. If you want to print the entire path with each line, like: / /another /another/deeper /another/more /another/wider /more /more/deeper /more/more /more/wider You could combine $Path and $Directory into one variable. I split them out to make it easy to paint just the name. Good luck... Rick Widmer Internet Marketing Specialists www.developersdesk.com

« previous php.general (#6867) next »