I've got this script that will read an input file of comma delimited server names, search the servers and determine the specified directory size, and output the result to a csv file. Now my only problem is when the script errors when it can't access a folder due to permissions, it then outputs a size of 0 for that directory. This isn't really correct because the directory might not be empty, it's just that it couldn't be accessed.
What I need to figure out is how to get the script to report "Error" (or something along those lines) in the output, instead of 0. Here is my code:
use File::Find;
use strict;
my ($dir, @parts);
open(IN, "< input.csv") or die("Couldn't open input.csv\n");
open(OUT, "> output.csv") or die("Couldn't open output.csv\n");
@parts=split (/,/,<IN>);
#Displays total size of specified path (total includes subfolders)
foreach my $dir (@parts) {
my $total;
print "\nWalking $dir\n";
find(sub { $total += -s }, $dir);
$total = ($total / 1024) / 1024;
$total = sprintf("%0.2f", $total);
print OUT "$dir, $total, mb, \n";
}
print "\n\tOutput created.\n";
close(OUT);
#Displays program syntax on screen
$dir = $ARGV[0];
Here is an example of the contents of the input file:
\\server\share,\\server\different_share,c:\temp