PHP recursively iterates through the files of the specified directory and counts the number of files, _php tutorial

Source: Internet
Author: User
Tags parent directory

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 ...

  • Related Article

    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.