Why can't this program traverse all the files and folders on the folder

Source: Internet
Author: User
Why can't this program traverse all the files and folders under the folder?
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 ');

?>

------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
------Solution--------------------
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!
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.