At 2:29 PM 6/25/97, Chris Nandor wrote: >At 10.44 6/25/97, Strider wrote: > >(snip) >>How does one find the size of a directory? I can't seem to find the >>function/command for it, and I'm really at a loss. > >I don't think there is a neat way to find the latter; I think you would >have to iterate through the directory structure and go file by file. As to >the former: > >#!perl >$dir="PowerPudgeII:"; >opendir(D,$dir) || die $!; >while(readdir(D)){$x++} >close(D); >print $x; >__END__ The file operator '-s' returns the number of files if tested against a directory, and the size in bytes if tested against a file. So, the following will check both the number of files in a given directory, plus the "size" of the directory in bytes: __BEGIN__ #!/usr/bin/perl $dir = "HD:some:directory"; # On UNIX, should be '/HD/some/directory' $total = 0; # Just initializing $size = (-s $dir); # Get the number of files in the dir print "Number of files in $dir: $size\n"; opendir (READ, $dir) || die; # Now open the directory while ($file = readdir(READ)) { # Get each file name $total += (-s "$dir:$file"); # Get the size and add. Note the delimiter } print "Total size of the $dir: $total bytes\n"; exit; __END__ Hope this helps. --Akira ~~~~~~~~~~~~~~~~~~~~~~~~~ AKIRA HANGAI ~~~~~~~~~~~~~~~~~~~~~~~~~ Network Connectivity Specialist Advanced Vet Systems akira@discover-net.net Phone: (715)834-0355 x220 http://www.advancedvet.com Fax: (715)834-0165 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ***** Want to unsubscribe from this list? ***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch