#!/bin/bash

SAVEIFS=$IFS
IFS=$(echo -en "\n\b")


counter=1

header1="<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\"><title>My Hobby</title>"
header2="<meta name=\"GENERATOR\" content=\"Microsoft FrontPage 6.0\"></head>  <body><p><font color=\"#FF0000\">"
header3="<font color=\"#FF0000\"><font size=\"7\">All File List</font></p>"

bottom="</body></html>"



function forAllFiles
{

        if  [ $1 != "unPublished.htm"  ];  then
		
		echo '<tr>'
		echo \<td width=20\>$counter\</td\>  \<td\> \<a href=\"http://www.staroceans.net/$1\"\>$1\<\/a\> \</td\>
		echo '</tr>'
		let "counter++"
	fi
}




function forAllDirs
{
 
directory="$1/$2"

	for f in $( ls $directory ); do
	
	    file="$directory/$f"

	    if [ -f "$file" ]; then
		forAllFiles "$2/$f"

	    else
		if  [ -d "$file" ];  then

		forAllDirs $1 "$2/$f"

		fi
	    fi
       done
}



arg=("$@")

    if [ $# -eq 1 ]; then
	dir=$1
	else
	dir=~/myweb
    fi	
	if [ -d $dir ]; then
#	    echo $header1 $header2 $header3
	    echo '<table border="1" cellpadding="5" cellspacing="5" width="100%">'
	    echo '<tr> <th> file index </th>  <th> file name </th>   </tr>'

	    for d in $( ls $dir ); do
		mydir="$dir/$d"
		if [ -d $mydir ]; then
		   
		    forAllDirs $dir $d

		else
		    if [ -f $mydir ]; then
			forAllFiles $d
			echo ""
		    fi
		fi
	    done	    
	    echo '</table>'
#	    echo $bottom
	fi
	
    
IFS=$SAVEIFS

