#!/usr/local/bin/perl -w #written by Nick (see http://illx.org for more details) #this script gives the status of a directory structure #how many files in what directory, and the size of those #files totalled #this script takes a directory as an argument #if no argument is given, it defaults to '.' use strict; use warnings; use File::Find; @ARGV = ('.') unless @ARGV; my %hash = (); my $cdir = undef; sub sorting { my $r = $File::Find::name; if(-d $_) { $hash{$r} = undef; $cdir = $r; } else { $hash{$cdir}->[0]++; $hash{$cdir}->[1]+= -s _; } } find(\&sorting, @ARGV); foreach my $k (sort keys %hash) { if(!$hash{$k}[0]) { print "$k : 0 files\n"; } else { my $size = sprintf('%.2f', (($hash{$k}[1] / 1024) / 1024)); print "$k : $hash{$k}[0] files - $size".'Mb'."\n"; } }