#!/usr/local/bin/perl5 -w
#  Simple Basic Open a Directory Example
#
require "cgi-lib.pl"; # Public Domain library to read form data
#
$statusofread =  &ReadParse(*formdata); # read data in associate array formdata
#
if( $statusofread )     { # If $statusofread nonzero, data read OK
        $dir = $formdata{"directory"}; # The input directory
}
#
$today =`date`;
chomp($today); # Today's date captured from UNIX
#
print <<EOF; # Generate the HTML responding page starting with HTTP line
Content-Type: text/html

<html>
<head>
<title>This is Result of my simple opendir CGI Script </title>
</head>
<body bgcolor="white" >
<h1>This Script lists directory $dir on a great $today</h1>
<font color=red size=7 > 
EOF
#
opendir(DIR,$dir) || die("\nSorry Could not open ",$dir," \n");
#
while( $name=readdir(DIR))      {
        next if( $name eq '.' || $name eq '..' ); # skip . and .. files
	print $name,"<br>\n"; # could select files by testing on names -- here just list
}
closedir(DIR);
#
print <<EOF; # Generate End of HTML Page
</font>
</body>
</html>
EOF
exit; # End Program
#
