#!/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). # 01/24/2007 njc - I'm now using qq( )qq instead of quote marks also I've added # a bunch of extra details to the css and html to make the # page more closely with the rest of the pages on the Linuxha # site (the new home of my pages). my ($fname, $fsize, $fdate); my ($dir, $name) = @ARGV; my $date = `date '+%A %B %d, %Y'`; defined($dir) || die "Must give directory to switch to.\n"; if(!defined($name)) { $name = "Linux Home Automation File Directory"; } chdir($dir) || die "Can not cd to $dir ($!)\n"; # This needs to be changed to read a file or something so we can hide # certain files a bit better open DIR, "ls -l|"; print "CD to $dir\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; # Compress perl files if($fname =~ /.*.pl$/) { $fname = $fname . ".gz"; } print "$fname - $fsize - $fdate \n"; } } } } close DIR;