Page 1 of 1

reading and output directories

Posted: Tue Feb 06, 2007 9:09 am
by andylyon87
pickle | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hey guys, its been a while ince I have needed to post but am back for some help.

I have a folder with x number of directories. I have no problem displaying these its the layer after that. ie. the directories in the first directories.

[syntax="php"]
$rep=opendir('.');//opens initial layer
	while ($file = readdir($rep)){//while loops the directories
		if($file != '..' && $file !='.' && $file !=''){ 
			if(is_dir($file)){ //then if $file is a dir
				
			$sub = opendir("$file"); //it opens that dir
			while ($subf = readdir("$sub/")){//its having a massive prob with this, basically I dont know what to ref
				if($subf != '..' && $subf !='.' && $subf !=''){//its then meant to check the sub folder for files
		
							if (is_dir("$rep/$subf")){	
				
				print("<tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>");
				print("<td width='100%'>");
				print("<a href='$subf/' target=_blank>$subf</a>");
				print("</td></tr>");
										}
										}
									}
		}
	}}
in summary I just want a script to look deeper than one layer of folders that isnt dependant on a certain number of folders on the base layer

Thanks for any help

Andylyon87


pickle | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Tue Feb 06, 2007 9:59 am
by volka
try

Code: Select all

<?php
function printdir($path) {
	echo '<ul>';
	foreach( glob($path.'/*') as $e ) {
		if ( is_dir($e) ) {
			echo '<li class="directory">', basename($e), '</li>';
			printdir($e);
		}
		else {
			echo '<li class="file">', basename($e), '</li>';
		}
	}
	echo '</ul>';
}
?>
<html>
	<head>
		<style type="text/css">
			li.directory { list-style-type:disc }
			li.file { list-style-type:circle }
		</style>
	</head>
	<body>
		<?php printdir('.'); ?>
	</body>
</html>
see also: http://en.wikipedia.org/wiki/Recursion_ ... science%29 and http://de3.php.net/glob