#!/usr/bin/perl -w # # $Revision: 1.4 $ $Date: 2009/11/03 02:55:20 $ # $UUID: 9e643f19-60d3-3d8b-9f9b-26eb0c259d16 $ # # read output from "ls -lR $PWD", write something resembling a sitemap. use File::Basename; use POSIX qw(strftime); use Fcntl ':mode'; use strict; my $myname = basename($0); $myname =~ s/\.\w*$//; # strip any extension my $docroot = '/doc/html/htdocs'; my $dir; my $file; my $path; # full pathname my $href; my $ftype; my $k; my ($mode, $links, $usr, $group, $size, $day, $when); # Header print <<'EndHeader';
EndHeader # TOC while (<>) { chomp; next if /^total/; # blank line? if (length() == 0) { print "\n"; next; } # is this a directory name at the top of a list? if (m!^(/.*):$!) { $path = $dir = $1; $dir =~ s!$docroot!!; $ftype = filetype("$path"); print "$ftype $dir\n"; } # is this a regular file listing with a pipe symbol? # -rw-r--r-- 1 user user 11936 17-Dec-1996 19:02:39| file... else { $k = index($_, '|'); ($mode, $links, $usr, $group, $size, $day, $when) = split(/\s+/, substr($_, 0, $k)); $file = substr($_, $k+2); $ftype = filetype("$path/$file"); $href = "$file"; # print everything ## printf "%10s %3d %8s %8s %8d %11s %8s %s\n", ## $mode, $links, $usr, $group, $size, $day, $when, $href; # print just size, date, and link. ## printf " %s %8d %11s %8s %s\n", $ftype, $size, $day, $when, $href; # print just filetype and link. print " $ftype $href\n"; } } # Footer $_ = strftime("%a, %d %b %Y %T %z", localtime(time())); my $vers = version(); print <<"EndFooter";
Generated by $vers | $_ |