<?php

// Expects:
//  $directory - the directory to list.

// Lists all readable files in the directory and its readable subdirectories

$directory = "/home/abu-jeib/www/teaching/Spring_07/207/";
list_dir($directory);

function list_dir($directory)
{
	if (@$dirHandle = opendir($directory))
	{
		echo "<ul>\n";
		while (($file_name = readdir($dirHandle)))
		{
			// Prevent processing files and directories that begin with a period 
			if ($file_name[0] != ".")
			{
				if (is_dir($directory."/".$file_name) && is_readable($directory."/".$file_name))
				{
					echo "<li>$file_name</li>\n";
					list_dir($directory."/".$file_name);
				
				}
				else if (is_readable ($directory . "/" .$file_name))
				{
					echo "<li>$directory" . "/" . $file_name . "</li>\n";
				}
			}
		}
		echo "</ul>\n";
		// Important: Don't include die or exit for closing the directory below.
		@closedir ($dirHandle);
	}
	else
	{
		echo "<p>ERROR: Couldn't read directory.</p>\n";
	}
}

?>

