#!/usr/bin/perl # print header print "Content-type: text/html\n\n"; # Determine OS and set a seperator $OS = $^O; if($OS =~ /win/i) { $isWIN = 1; } else {$isUNIX = 1;} if($isWIN){ $S{S} = "\\\\"; } else { $S{S} = "/";} # enter starting point my $size = &getServerSize("/home/sbremner/public_html/dazman"); # print size returned print qq~Total size = $size~; sub getServerSize { my ( %VAR, @folder, @dirs ); $VAR{startAt} = shift; if($VAR{startAt}){ $VAR{totalSize} = 0; $VAR{reading} = 1; $VAR{folder} = $VAR{startAt}; @dirs = ($VAR{folder}); while($VAR{reading}){ # remove current from server search $VAR{current} = shift(@dirs); opendir(D, $VAR{current}); @folder = readdir(D); closedir D; foreach(@folder) { unless($_ eq '.' || $_ eq '..') { if(-d "$VAR{current}$S{S}$_") { # add sub folders to server search push(@dirs, "$VAR{current}$S{S}$_"); } else { $VAR{totalSize} += -s qq~$VAR{current}$S{S}$_~; } } } $VAR{reading} = 0 unless $dirs[0]; } } $VAR{totalSize} = $VAR{totalSize} / 1024; $VAR{totalSize} = sprintf("%5.2f", $VAR{totalSize}); $VAR{totalSize} =~ s/\s+//ig; 1 while $VAR{totalSize} =~ s/(.*\d)(\d\d\d)/$1,$2/g; $VAR{totalSize} .= qq~kb~; return $VAR{totalSize};