recurse_dirsize

Definition:
function recurse_dirsize( $directory ) {}

Get the size of a directory recursively.
Used by get_dirsize() to get a directory’s size when it contains other directories.

Parameters

  • string $directory

Source code

function recurse_dirsize( $directory ) {

	$size = 0;



	$directory = untrailingslashit( $directory );



	if ( !file_exists($directory) || !is_dir( $directory ) || !is_readable( $directory ) )

		return false;



	if ($handle = opendir($directory)) {

		while(($file = readdir($handle)) !== false) {

			$path = $directory.'/'.$file;

			if ($file != '.' && $file != '..') {

				if (is_file($path)) {

					$size += filesize($path);

				} elseif (is_dir($path)) {

					$handlesize = recurse_dirsize($path);

					if ($handlesize > 0)

						$size += $handlesize;

				}

			}

		}

		closedir($handle);

	}

	return $size;

}

2635

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: