#!/usr/bin/perl -w
# dirlist.pl
use strict;

# This script puts an html file in each directory, with a link to each
# file that matches the list of filetypes.

# just declare the variables used later on
my $dirname;
my $filetype;
my $titles;

###########################
# Begin editable variables
###########################

# Filetypes to include
my @filetypes=qw(pdf PDF txt);


# Directories to scan
my @dirnames=
qw(

./
test/

);


# Specify a title to go with each of the directories

my %titles=(

"./"       =>    "Dot",
"test/"    =>    "Test Directory"

);


# filename of the HTML file to create
my $filename="index.html";

#########################
# End editable variables
#########################



foreach my $dirname (@dirnames)

{

   chdir $dirname;

   open FH, ">$filename" or die $!;


   print FH "
<html>\n
<head><title>$titles{$dirname}</title></head>\n
<body bgcolor=\"#FFFFFF\">\n\n";

   for my $filetype (@filetypes) { 
      for (<*.$filetype>) {
         print FH "<h1>$titles{$dirname}</h1>\n";
         
         print FH "<a href=\"";
         print FH $_;
         print FH "\">";
         print FH $_;
         print FH "</a>";
         #print FH " ($filetype file)";
         #Attempt to use file(1) to find out what type of file:
         print FH `file $filename | sed "s/[^:]*//"`;
         print FH "\n";
      }
   }


print FH "
</body>\n
</html>\n";
close FH;
chdir "..";
}


