The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

File::Size - Get the size of files and directories

SYNOPSIS

Get the size for directory /etc/ with the block size of 1024 while following symbolic links:

 my $obj = File::Size->new(
    dir            => '/etc/',
    blocksize      => 1024,
    followsymlinks => 1,
    humanreadable  => 1
 );
 print $obj->getsize(), "\n";

DESCRIPTION

File::Size is used to get the size of files and directories.

There are 6 methods you can use:

new
 There are 4 optional hash values for the new() method:
dir

The directory you want the module to get the size for it. Default is current working directory.

blocksize

The blocksize for the output of getsize() method. default is 1 (output in bytes).

If you want to follow symlinks for directories and files, use this option. The default is not to follow symlinks.

humanreadable

If you want output size in human readable format (e.g. 2048 -> 2.0K), set this option to 1.

 You don't have to specify any of those options, which means this is okay:
     print File::Size->new()->getsize(), " bytes\n";
 This is okay too:
     print File::Size->new()->setdir( '/etc/' )->setblocksize( 1024**2 )->getsize(), " MB\n";
setdir

Used to set (or get - if called without parameters) the directory. Example: $obj->setdir( '/etc/' );

setblocksize

Used to set (or get - if called without parameters) the block size. Example: $obj->setblocksize( 1024 );

Used to set if you want to follow symbolic links or not. If called without parmeters, returns the current state. Example: $obj->setfollowsymlinks( 1 );

sethumanreadable

Used to set (or get - if called without parameters) if you want human-readable output sizes. Example: $obj->sethumanreadable( 1 );

getsize

Used to calculate the total size of the directory. Prints output according to the block size you did or didn't specify.