#!/usr/bin/perl -w # $currpath is the current relative path # $rootpath is the starting absolute path # @contents is the data returned from ls -alR # $line is each line of @contents # %fileindex is a hash containing keys => values of filenames => paths # %filetstamp is a hash containing keys => values of filenames => timestamps # %filesize is a hash containing keys => values of filenames => sizes in bytes $rootpath = `pwd`; $rootpath =~ s/\n//g; $currpath = ''; @contents = `ls -alR`; foreach $line (@contents) { if ($line =~ /^\-/) { # Process file listing ($perm, $num, $own, $grp, $size, $mon, $day, $yrtm, $file) = split(/\s+/, $line); if (!($file =~ m/\.htm(|l)$/i)) { next; } if (exists $fileindex{$file}) { $filen = "$file.1"; } else { $filen = $file; } $fileindex{$filen} = "$rootpath/$currpath/$file"; $filetstamp{$filen} = "$mon $day $yrtm"; $filesize{$filen} = $size; } if ($line =~ /^\.\//) { # Process new directory $currpath = $line; $currpath =~ s/^\.\///g; # Pull out ./ from the beginning $currpath =~ s/\n//g; # Pull out any newline characters $currpath =~ s/\:$//g; # Pull out : from the end } } # Sort all and output to file open(OUTFILE, ">InformCap.out.txt") or die("Couldn't open file..."); foreach $key (sort { lc($a) cmp lc($b) } keys %fileindex) { $filen = $key; $fullname = $fileindex{$key}; $timestamp = $filetstamp{$key}; $size = $filesize{$key}; while ($filen =~ /\.1$/) { $filen =~ s/\.1$//g; } while (length($filen) < 25) { $filen = "$filen "; } while (length($timestamp) < 15) { $timestamp = "$timestamp "; } $size = "$size "; while (length($size) < 10) { $size = " $size"; } print OUTFILE "$filen $size $timestamp $fullname\n"; } close(OUTFILE);