Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@hikiko
Last active April 11, 2019 09:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hikiko/374b7a9353bda967edf293e667c0412c to your computer and use it in GitHub Desktop.
Save hikiko/374b7a9353bda967edf293e667c0412c to your computer and use it in GitHub Desktop.
creates a toc.html file with links to each file of a given directory, inside the directory.
#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
use Getopt::Long;
my $dir = ".", my $help;
GetOptions("d=s" => \$dir,
"h" => \$help);
if ($help) {
print qq[Help:
-d <directory>, where to create the toc html
-h print this help and exit]."\n";
exit;
}
if (!(-d $dir)) {
die "$dir is not a directory!\n";
}
opendir(DIR, $dir) or die $!;
my @files = (readdir DIR) or die $!;
closedir(DIR) or die $!;
if ($dir =~ m/(^.*)\/$/) {
$dir = $1;
}
my $fname = qq[$dir/toc.html];
open FILE, ">", $fname or die $!;
print FILE qq[<html>
<head>
<style>
body {
background-color: #000111;
color: #19F104;
font-size: large;
font-family: Mono
}
a:link {
color: #179FD2;
}
a:visited {
color: #69ACB3;
}
a:hover {
color: #EBC113;
}
a:active {
color: #EBC113;
}
</style>
</head>
<body>];
foreach (@files) {
next if ($_ eq "." || $_ eq "..");
next if ($_ eq "toc.html");
next if (-d $_);
print FILE qq[<a href="$_">$_</a><br/>];
}
print FILE qq[
</body>
</html>];
close FILE or die $!;
print "Filenames of: $dir were written to: $fname\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment