in reply to Re: folder size
in thread folder size

Another way to get Size of files in folder(s).
Hi Sandor

use 5.006;
use strict;
use warnings;
use File::Glob ':glob';

if (scalar @ARGV== 0) {die "folderSize.pl \t-s <foldername> <foldername> \n\t\t -s  scan subfolders\n"};
my $foldersize=0;
my @folders=@ARGV;
my $subfolder="";

if ($ARGV[0] eq "-s") {$subfolder=shift @ARGV; @folders=@ARGV;}
print "Folders @folders\n";

for my $folder (@folders){
     printf STDERR "Size of folders=%10d\r" ,$foldersize;
     unless (-e $folder) {print STDERR "Folder does not exist $folder\n"; next}
     $folder=~s/\/$//;
     $folder=~s/\\$//;
     my @entries=glob("$folder/*");
     for (@entries){
	 if (-d){
#	         print STDOUT "folder $_\n" ;
	          push @folders, $_ if $subfolder;
	         }
	 else   {
#	         print STDOUT "file : $_ \tsize:".(stat)7."\n";
	         $foldersize+=(stat)7;
         }
      }
 }

print "Size of files in folder(s) @ARGV is =$foldersize bytes";

Replies are listed 'Best First'.
Re^3: folder size
by Anonymous Monk on Jul 18, 2010 at 12:08 UTC
    USAGE :folderSize.pl [-s] <foldername> [<foldername] To get the file size use: (stat)[7] in the previous script.(Jul 18, 2010 at 11:54 UTC) Sandor