#!/usr/bin/perl # # quick script to generate an index.html file from a directory listing ## use strict; use Cwd; my ($dir, @dirs, @files, $fh); my $description = "genindexhtml will generate an index.html file from a directory listing\n"; my $usage = 'usage: genindexhtml ' . "\n" . 'if no directory is specified, cwd is used'; if ($ARGV[0]) { if ($ARGV[0] =~ "^-") { print "\n$description"; print "\n$usage\n\n"; exit(0); } else { $dir = $ARGV[0]; } } else { $dir = getcwd; } opendir(DIRHANDLE, "$dir") || die "Cannot opendir $dir: $!"; foreach my $name (sort readdir(DIRHANDLE)) { if (($name =~ /^\./) || ($name eq 'index.html')) { next; } if (-d "$dir/$name") { push @dirs, "\"[DIR]\" $name
\n"; } else { push @files, "\"[ $name
\n"; } } closedir(DIRHANDLE); my $header = " Directory Index \n

Directory Index

\n
Icon  Name

"; my $footer = "
\n"; open ($fh, ">$dir/index.html") or die "can't create $dir/index.html: $!\n"; print $fh $header; print $fh @dirs; print $fh @files; print $fh $footer; chmod (0644, $fh) or warn "error: couldn't chmod $dir/index.html, permissions may not be set properly\n$!\n"; close ($fh);