recurse_dirsize( string $directory, string $exclude = null )
Get the size of a directory recursively.
Description Description
Used by get_dirsize() to get a directory’s size when it contains other directories.
Parameters Parameters
- $directory
-
(string) (Required) Full path of a directory.
- $exclude
-
(string) (Optional) Full path of a subdirectory to exclude from the total.
Default value: null
Return Return
(int|false) Size in MB if a valid directory. False if not.
Source Source
File: wp-includes/ms-functions.php
function recurse_dirsize( $directory, $exclude = null ) { $size = 0; $directory = untrailingslashit( $directory ); if ( ! file_exists( $directory ) || ! is_dir( $directory ) || ! is_readable( $directory ) || $directory === $exclude ) { 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, $exclude ); if ( $handlesize > 0 ) { $size += $handlesize; } } } } closedir( $handle ); } return $size; }
Expand full source code Collapse full source code View on Trac
Changelog Changelog
Version | Description |
---|---|
MU (3.0.0) | MU (3.0.0) |
4.3.0 | Introduced. |