Фрагмент DirTreeSize.pl
sub ProcessDir
{
my( $Dir ) = @_;
my( @DirList, @FileList );
if( opendir( DIR, $Dir ) )
{
while( my $Object = readdir( DIR ) )
{
next if( «.» eq $Object || «..» eq $Object );
my $Path = «$Dir$Object»;
if( -f $Path )
{
push( @FileList, $Path );
}
elsif( -d $Path )
{
push( @DirList, $Path );
}
}
closedir( DIR );
}
foreach my $Path ( sort @FileList )
{
ProcessFile( $Path );
}
foreach my $Path ( sort @DirList )
{
# Begin Callout A
$giCountDir++;
UpdateDisplay();
ProcessDir( $Path );
# End Callout A
}
}
sub ProcessFile
{
my( $Path ) = @_;
my @Stats = stat( $Path );
# Begin Callout B
$giSize += $Stats[7];
$giCountFile++;
UpdateDisplay();
# End Callout B
}
sub UpdateDisplay()
{
# Begin Callout C
printf( «Files: % 7s Dirs: % 4s TotalSize: %s bytes (%s bytes)
»,
FormatNumber( $giCountFile ), FormatNumber( $giCountDir ),
FormatNumberPretty( $gSize ), FormatNumber( $gSize ) );
# End Callout C
}