#!/usr/bin/perl # Directory indexer. # perl dir_index.pl directory_path 'Title' # # directory_path is required but 'Title' can be ignored and defaults to # "Directory Index page" # 06/01/2003 njc - I needed a program to create directory indexing as Comcast # doesn't permit access to the directories directly. I may add # a description file describing each program (later). my ($fname, $fsize, $fdate); my ($dir, $name) = @ARGV; defined($dir) || die "Must give directory to switch to.\n"; if(!defined($name)) { $name = "Directory Index page"; } chdir($dir) || die "Can not cd to $dir ($!)\n"; open OUT, ">index.html"; open DIR, "ls -l|"; print OUT "\n"; print OUT "$name\n"; print OUT "
$name

\n\n"; while() { chomp; if(/^-/) { # file always start with - if(!(/$\~/)) { # Ignore file ~ as they are tmp files #-rw-rw-r-- 1 njc njc 36347 May 14 09:29 www.foo #-rwxrwxr-x 1 njc njc 5246 Oct 26 2002 telnet.pl if(/.*?\s\d{1,}\s\w{1,}\s{1,}\w{1,}\s{1,}(\d{1,})\s(\w{1,}\s{1,}\d{1,}\s{1,}[:0-9]{1,})\s(.*)$/) { $fsize = $1; $fdate = $2; $fname = $3; print OUT "\n"; } } } } print OUT "
 $fname$fsize$fdate

\n"; close DIR; close OUT;