Real Perl has asked for the wisdom of the Perl Monks concerning the following question:
Also, if the total of bytes are greater than 3.999GB, Perl cannot handle it (see explanation below).my $Size = best_convert( my $SizeUnit, $DirInfo->{HighSize}, $DirInfo->{LowSize}, ); print "Dir size = $Size $SizeUnit \n";
I have been experimenting with printing the total in the appropriate unit in a separate file and here is the codesub make_table(){ $table=$page3->Scrolled('HList',-columns=> 2,-header=> 1,-width=>3 +1,-height=>9,-font=>"Times 12",-scrollbars=>'osoe') ->place(-x=> 280, -y=> 136); $table ->headerCreate(0, -text=>" Directory "); $table ->headerCreate(1, -text=>" Size "); open(BATCHIN, "<batch.txt") or die;#open bacth $source =~s/\//\\/g; while(<BATCHIN>){ chomp; @arraybatch = split ' '; #put each line in an array to use whe +n I invoke the size calculation method foreach (@arraybatch){ my $cleansource = $source; $cleansource .= "\\"; $cleanso +urce .= $_; #append the \\ and the user directory $sourceResult = dir_size($cleansource, $sourceDirInfo,);#g +et the size of the directory $sbyte += $sourceDirInfo->{DirSize}; #add the bytes of all + of the directories $sourceSize = best_convert($sourceSizeUnit, $sourceDirInfo +->{HighSize}, $sourceDirInfo->{LowSize},);#converts my $s = $sourceSize;#append the size $s .= $sourceSizeUnit;#appends the unit to the size $table->add($_); $table->itemCreate($_, 0, -text => $_); $table->itemCreate($_, 1, -text => $s); }#foreach }#while }#make_table
#!/usr/bin/perl -w use strict; use Win32::DirSize; use integer; my $sourcesize="Total: "; my $sbyte=0; my $test = "C:/"; $test=~s/\//\\/g; print $test; my $Result = dir_size( $test, my $DirInfo, # this stores the directory information ); $sbyte = $DirInfo->{DirSize}; print "Dir size = $sbyte bytes\n"; if ($sbyte < 1024){ $sourcesize .= "$sbyte B"; print $sourcesize; } elsif (1024 <= $sbyte && $sbyte < 10240){ $sbyte=$sbyte/1024; $sourcesize .= "$sbyte KB"; print $sourcesize; }elsif (10240< $sbyte && $sbyte < 1073741824){ $sbyte=$sbyte/1048576; $sourcesize .= "$sbyte MB"; print $sourcesize; }else{ print "More than 3.99GB";}#else
Claire
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Win32::DirSize and GB amount of data
by BrowserUk (Patriarch) on Aug 11, 2005 at 00:16 UTC |