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";
File::Size is used to get the size of files and directories.
There are 6 methods you can use:
There are 4 optional hash values for the new() method:
The directory you want the module to get the size for it. Default is current working directory.
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.
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(), " bytesn";
This is okay too:
print File::Size->new()->setdir( '/etc/' )->setblocksize( 1024**2 )->getsize(), " MBn";
Used to set (or get - if called without parameters) the directory. Example: $obj->setdir( '/etc/' );
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 );
Used to set (or get - if called without parameters) if you want human-readable output sizes. Example: $obj->sethumanreadable( 1 );
Used to calculate the total size of the directory. Prints output according to the block size you did or didn't specify.