rendered paste body#!/usr/bin/perl
use CGI;
#change this to the full pathname to the bottom of the dir structure:
my $dir = ".";
print "Content-type: text/html\n\n";
my $cgiin = CGI->new;
my $letter = $cgiin->param('letter');
if (($letter eq "") && ($ARGV[0] =~ /[\w|\.]/)) {
$letter = $ARGV[0];
print "Running from the command line, looking for things that start with $letter\n";
}
if ($letter !~ /[\w|\.]/) {
print "<h2>Please specify a valid letter</h2>";
die "Invalid letter given";
}
my @errors;
#my $givendir = $ARGV[0];
#if ($givendir eq "") {
$givendir = ".";
#}
opendir('FLIST', ".");
my @dirs = readdir('FLIST');
closedir('FLIST');
while(@dirs) {
my $workdir = shift(@dirs);
while(($workdir eq '.') || ($workdir eq '..')) {
$workdir = shift(@dirs);
}
opendir('CURDIR', "$workdir");
my @prefilelist = readdir('CURDIR');
closedir('CURDIR');
my @filelist;
while(@prefilelist) {
my $workline = shift(@prefilelist);
if (($workline ne '.') && ($workline ne '..')) {
push(@filelist, "$workline");
}
}
my $numfiles = @filelist;
if ($numfiles != 1) {
push(@errors, "in $workdir: expected 1 file, found $numfiles");
} else {
if (($workdir =~ /^($letter)/i) || (($letter eq '.') && ($workdir =~ /^\d/))) {
print "<a href=\"/cgi-bin/download.pl?filename=$workdir\">$workdir</a><br />\n";
} else {
print "Not matching $workdir because it doesn't start with a $letter<br />\n";
}
}
}
#my $numerrors = @errors;
#if ($numerrors != 0) {
# print "WARNING: $numerrors reported errors:\n";
#}
#while(@errors) {
# my $errorline = shift(@errors);
# print "$errorline\n";
#}