#!/usr/bin/perl use strict; use warnings; use POSIX qw/strftime/; my $outputfile = "/home/swflint/org/index.org"; my $date = strftime "<%Y-%m-%d %a %H:%M>", localtime; my $fileHeader = <", $outputfile) or die "Unable to open \"$outputfile\" the output file, $!"; print $output $fileHeader; opendir(my $directory, "/home/swflint/org/") or die "Can't open the directory: $!"; my @directories; while (my $file = readdir $directory) { if ($file =~ m/^\..*/) { next; } elsif (-d "/home/swflint/org/$file") { push @directories, $file; } elsif ($file =~ m/.*\.org$/) { (my $linkName = $file) =~ s/\.[^.]+$//; $linkName =~ s/-/ /g; $linkName =~ s/\b(\w)/\U$1/g; print $output " - [[file:~/org/$file][$linkName]]\n" } else { next; } } closedir $directory; foreach (sort @directories) { my $newDir = $_; if ($newDir =~ "auto" or $newDir =~ "data") { next; } opendir(my $theDirectory, "/home/swflint/org/$newDir/") or die "Can't open directory: $!"; my $fancyDir = $newDir; $fancyDir =~ s/-/ /g; $fancyDir =~ s/\b(\w)/\U$1/g; print $output "\n** Org: $fancyDir\n\n"; print $output " - [[file:~/org/$newDir/][$fancyDir]]\n"; while (my $file = readdir $theDirectory) { if ($file =~ m/^\..*/ or -d "/home/swflint/org/$newDir/$file") { next; } elsif ($file =~ m/.*\.org$/) { (my $linkName = $file) =~ s/\.[^.]+$//; $linkName =~ s/-/ /g; $linkName =~ s/\b(\w)/\U$1/g; print $output " - [[file:~/org/$newDir/$file][$linkName]]\n"; } else { next; } } } close $output;