Below is a program that calculates the size of all files and folders under the folder, I let it calculate the size of the folder ' Znb1 ', under this folder
The structure for
Znb1/.buildpath,
Znb1/.project,
znb1/223/s.php,
znb1/settings/newfile.php,
Znb1/settings/org.eclipse.php.core.prefs
Only the size of the Znb1/.buildpath and znb1/.project two files is calculated after the program is run
Why is this? I use the software for the Wampserver and EditPlus programs as follows:
function Dirsize ($dirname) {
$dir = Opendir ($dirname);
while (($file = Readdir ($dir))!== FALSE) {
$filename = $dirname. ' \ \ '. $file;
if ($file! = '. ' && $file! = ' ... ') {
if (Is_dir ($file)) {
$count + = Dirsize ($file);
} else {
$count + = FileSize ($filename);
}
}
}
return $count;
}
echo dirsize (' znb1 ');
?>
Reply to discussion (solution)
if (Is_dir ($filename)) {
If it is $file, then for this relative path, it will be found in the current directory. No natural report found false
Must take the path!
if (Is_dir ($filename)) {
$count + = Dirsize ($filename);
Set_time_limit (0);
function Dirsize ($dirname) {
if (Is_dir ($dirname)) {
$dir = Opendir ($dirname);
if ($dir! = False) {
while (($file = Readdir ($dir))!== FALSE) {
$filename = $dirname. ' \ \ '. $file;
if (Is_file ($filename)) {
$count [] = FileSize ($filename). " @ ". $filename;
} else if (Is_dir ($filename)) {
if ($file! = "." && $file! = "...") {
Dirsize ($filename);
}
}
}
}
return $count;
} else {
return false;
}
}
$path = "D:\APMServ5.2.6\www\htdocs\localhost";
$c = Dirsize ($path);
Var_dump ($c);
+-----------------------------------------------------------------+
Modified a bit, you can calculate the relative road strength has not been tested!
I'll give you a function to traverse the folder.
You can refer to: http://www.bacysoft.cn/thread-77-1-1.html