PHP recursively iterates through the files of the specified directory and counts the number of files,
This example describes how PHP recursively iterates through the files of a specified directory and counts the number of files. Share to everyone for your reference. The implementation method is as follows:
<?php//recursive function implementation traverse the directory and the number of files under the specified file function total ($dirname,& $dirnum,& $filenum) { $dir =opendir ($dirname); echo Readdir ($dir). "
"; Read the current catalog file echo readdir ($dir). "
"; Read the parent directory file while ($filename =readdir ($dir)) { //To determine if the path under $dirname is a directory $newfile = $dirname. " /". $filename; The Is_dir () function determines whether the path of the current script is the directory if (Is_dir ($newfile)) { //through a recursive function and then iterates through the directory or file under its subdirectory ($newfile, $dirnum, $ FileNum); $dirnum + +; } else{ $filenum + +; } } Closedir ($dir);} $dirnum =0; $filenum =0;total ("E:/appserv/www/phpmyadmin", $dirnum, $filenum); echo "Total directory:" $dirnum. "
"; echo" Total Files: ". $filenum."
";//traverse the specified file directory and the number of files ends?>
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/972636.html www.bkjia.com true http://www.bkjia.com/PHPjc/972636.html techarticle PHP recursively iterates through the files of the specified directory and counts the number of files, and this example describes how PHP recursively iterates through the files of the specified directory and counts the number of files. Share to everyone ...