Why can't this program traverse all the files and folders in the folder?
Source: Internet
Author: User
Why can't this program traverse all files and folders in a folder? The following is a program that calculates the size of all files and folders under a folder. I asked it to calculate the size of the 'znb1 'folder. the structure below this folder is znb1 /. buildpath, znb1 /. project, znb1/223/s. php, znb1/set: why cannot I traverse all files and folders in a folder?
The following is a program that calculates the size of all files and folders under a folder. I want it to calculate the size of the 'znb1 'folder.
The structure of IS
Znb1/. buildpath,
Znb1/. project,
Znb1/223/s. php,
Znb1/settings/newfile. php,
Znb1/settings/org. eclipse. php. core. prefs
After the program runs, only the sizes of znb1/. buildpath and znb1/. project are calculated.
Why? The software I use is wampserver and editplus as follows:
Function dirsize ($ dirname ){
$ Dir = opendir ($ dirname );
While ($ file = readdir ($ dir ))! = FALSE ){
$ Filename = $ dirname. '\'. $ file;
If ($ file! = '.' & $ File! = '..'){
------ Solution --------------------
If (is_dir ($ filename )){
If it is $ file, the relative path will be searched in the current directory. False if not found
------ 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 );
+ ----------------------------- +
After a modification, we can calculate it. we haven't tested the relative strength! For more information, see!
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