#!/usr/bin/perl use strict; use warnings FATAL => qw( all ); use CGI::Carp qw(fatalsToBrowser); use List::Util qw(sum min max); use URI::Encode qw(uri_encode); use lib 'files/lib'; use Base::HTML::Elements qw(table); # I would add this in, however, it is just too big. # print_menu was taken out for this example. # link_color applies color styles to links based on file extension. # I included link_color below. use Base::Menu qw(print_menu link_color); # Gets root data for my site. You can get rid of this. use Base::Roots qw(get_root); # Adds commas and rounds numbers. use Base::Number qw(pretty_number); use Base::Nifty qw(line); print "content-type: text/html \n\n"; # change this to the path of whatever directory you want. my $root_path = get_root('path'); my %extensions; my %file_sizes; my $file_sizes_sum; sub file_list { my $directory = shift; opendir(my $dir,$directory) or die "Can't open $directory $!"; my @temp = grep {/^\w/} readdir($dir); for (@temp) { if (-f "$directory/$_") { my $key = (split(/\./,$_))[-1]; ++$extensions{$key}; my $file_size = -s "$directory/$_"; my $file = "$directory/$_"; $file =~ s/$root_path\///; $file_sizes{$file}{bytes} = $file_size; $file_sizes{$file}{kilobytes} = $file_size/1024; $file_sizes{$file}{megabytes} = ($file_size/1024)/1024; $file_sizes_sum += $file_size; } if (-d "$directory/$_") { file_list("$directory/$_"); } } } file_list("$root_path"); my $extensions_sum = sum(values %extensions); my $extensions_types = keys %extensions; my $file_sizes_total = keys %file_sizes;