#!/usr/local/bin/perl -wT # files_list.cgi # by pms@netdoor.com # Lists files with links and stats, in un m. # To do: small/med/large files - MB vs KB vs Bytes # print out list of files in a web page # Use: # or ################################################## # Settings ################################################## # Directory to work in. my $files_dir = '.'; # Type of files to list. my $type = ".zip"; ################################################## # Main Program ################################################## $| = 1; use strict; # Predefining variables. my (@dir, $file, %File_Sizes, $total_bytes, $total_megabytes, $rounded_size, $mean, $key); opendir (DIR, $files_dir); @dir = grep /$type/, readdir DIR; closedir DIR; @dir = sort {$a cmp $b} @dir; # Number of files. my $file_count = scalar(@dir); # Why I have to have this when this is a SSI, I have no idea. print "Content-type: text/html\n\n"; # Getting info about files. foreach $file (@dir) { my @entry = stat($file); my $bytes = $entry[7]; $File_Sizes{$file} = $bytes; $total_bytes += $bytes; } print "
Files: $file_count
\n];
$total_megabytes = $total_bytes / 1000000;
$rounded_size = sprintf("%.1f", $total_megabytes);
print "Total Size: $rounded_size MB
\n";
$mean = ($total_bytes / $file_count) / 1000000;
$rounded_size = sprintf("%.1f", $mean);
print "Arithmetic Mean: $rounded_size MB