2009/3/3 Wagner, David --- Senior Programmer Analyst --- CFS <david.wag...@freight.fedex.com>: >> -----Original Message----- >> From: lauri.nikki...@gmail.com >> [mailto:lauri.nikki...@gmail.com] On Behalf Of Lauri Nikkinen >> Sent: Tuesday, March 03, 2009 11:38 >> To: Perl Beginners >> Subject: Printing directory sizes >> >> Hi, >> >> I'm trying to print directory sizes using script from >> >> http://coding.derkeiler.com/Archive/Perl/perl.beginners/2005-0 >> 8/msg00693.html >> >> and when I try it from the cmd.exe >> >> C:\Perl>perl Print_directory_sizes.pl "C:/Temp" >> >> but I get an error message saying >> >> use of uninitialized value.... etc. >> >> Where is the problem? I'm using Win XP. >> >> ---code--- >> #!/bin/perl >> >> use warnings; >> use strict; >> use File::Find::Rule; >> >> my $dir = $ARGV[0]; >> my $size; >> >> find( sub { -f and ( $size += -s _ ) }, $dir ); >> ---code--- > I took the code and removed the ::Rule and left the other and it > ran fine, but did not print anything. So I add a print statement for the > $size and it worked without any error msgs,etc and it gve the right > values. > > What actually happens when you run? Not just the use of uni.. > but all the output.
I think what Lauri is after, is the accumulated total of all the files with a directory, something like this perhaps: #!/bin/perl use strict; use warnings; use File::Find; my $dir = shift; die "You must supply a full directory path" unless (-e $dir && -d $dir); my $total_size_of_files_in_dir; find(\&wanted, $dir); print "The total size of the file in $dir is $total_size_of_files_in_dir bytes\n"; sub wanted { if (-f $_) { $total_size_of_files_in_dir += -s; } } A recursive example might be a better tool though. Dp. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/