recurse_dirsize() - WordPress 函数参考中文文档

返回介绍

recurse_dirsize()

发布于 2017-09-11 字数2176 浏览 814 评论 0

recurse_dirsize( string $directory,  string $exclude = null )

Get the size of a directory recursively.


描述

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


参数

$directory

(string)
(Required)
Full path of a directory.

$exclude

(string)
(Optional)
Full path of a subdirectory to exclude from the total.

Default value: null


返回值

(int|false) Size in MB if a valid directory. False if not.


源代码

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;
}

更新日志

Version 描述
MU MU
4.3.0 Introduced.

相关函数

Uses

  • wp-includes/formatting.php:
    untrailingslashit()
  • wp-includes/ms-functions.php:
    recurse_dirsize()

Used By

  • wp-includes/ms-functions.php:
    get_dirsize()
  • wp-includes/ms-functions.php:
    recurse_dirsize()

User Contributed Notes

上一篇:rawurlencode_deep()

下一篇:redirect_canonical()

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!