Thank you for your post. That is quite there but not enough. See, I have
these directories and files in my C:\Perl\ folder
Volume in drive C has no label.
Volume Serial Number is 248A-0894
Directory of C:\Perl
04.03.2009 19:18 <DIR> .
04.03.2009 19:18 <DIR> ..
03.03.2009 21:41 <DIR> bin
03.03.2009 21:24 <DIR> cpan
03.03.2009 21:40 <DIR> eg
03.03.2009 21:42 <DIR> etc
03.03.2009 21:41 <DIR> html
03.03.2009 21:41 <DIR> lib
03.03.2009 21:40 <DIR> man
03.03.2009 20:23 <DIR> OmatPerlit
03.03.2009 22:09 225 Print_directory_sizes.pl
01.10.2008 18:00 <DIR> site
04.03.2009 19:18 0 text.txt
2 File(s) 225 bytes
11 Dir(s) 28ÿ409ÿ733ÿ120 bytes free
And I would like to write to script which prints into STDOUT (=cmd screen)
all the directories in this folder (C:\Perl\) and and their size. So the out
put should look like this:
Directory bin: size xxx megabytes
Directory cpan: size xxx megabytes
Directory eg: size xxx megabytes
Directory etc: size xxx megabytes
...and so on
Even better, if I could print out all the subdirectories also.
-L
2009/3/4 Dermot <[email protected]>
> 2009/3/3 Wagner, David --- Senior Programmer Analyst --- CFS
> <[email protected]>:
> >> -----Original Message-----
> >> From: [email protected]
> >> [mailto:[email protected]] 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.
>