sub listDirectory
{
	($dir)=@_;
	my $buf="";

	$url=$dir;
	$url=~s/^$htdocs//g;
	$url=~s/\/\//\//g;

	$buf.="<html><head><title>Listing of dir $url</title></head><body>\n";
	$buf.="Directory listing:<br><br><tt>\n\n";
	@files=split ('\n',`ls $dir`);
	$updir=$url; 
	#$updir=~/^[.*\/(.*)]*[\/]$/;
	$updir=~s/\/.*\/$/xx/; # TODO
	#$updir=$1;
	$url=~s/\/\//\//;
	$url=~s/\/$//;

	if ($dir=~/\//)
	{
		$buf.="[D] <a href=\"$url/\">./</a><br>\n";
		$buf.="[D] <a href=\"$updir/\">../</a><br>\n";
	}
	foreach $i (@files)
	{
		# Fetch file information
		($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,
	     $size,$atime,$mtime,$ctime,$blksize,$blocks)=stat("$dir/$i");
		($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime($mtime);
		$year+=1900;
		$mon+=1;
		$date="$year-$mon-$mday";
		if ( -d "$dir/$i" ) {
			$buf.="[D] <a href=\"$url/$i\">$i/</a><br>\n";
		} else {
			$buf.="[F] <a href=\"$url/$i\">$i</a> -   ";
			$buf.="LastMod: $date -  Size: $size Bytes<br>\n";
		}
	}
	$buf.="</tt><hr>Screws v$ENV{VERSION}</body></html>";

	printBuffer($buf,0);
}

return 1;
