PHP custom Traverse Directory All Files method _php tutorial

Source: Internet
Author: User
PHP custom traversal of all files in the directory method
Header (' Content-type:text/html;charset=utf-8 ');
/**
* method One: Use Readir () to traverse the directory
*/
function Listdir ($dir)
{
if (Is_dir ($dir))
{
if ($handle = Opendir ($dir))
{
while ($file = Readdir ($handle))
{
if ($file! = '. ' && $file! = ' ... ')
{
if (Is_dir ($dir. Directory_separator. $file))
{
Echo ' Directory name: '. $dir. Directory_separator. " $file. '
';
Listdir ($dir. Directory_separator. $file);
}else{
echo ' filename: '. $dir. Directory_separator. $file. '
';
}
}
}
}
Closedir ($handle);
}else{
echo ' Non-valid catalog! ';
}
}
Listdir ('./phpmyadmin ');

 /** 
* Method Two: Use Dir () to traverse the directory
* DIR () function and return to the Directory class instance on Success
*/
Function tree ( $dir ) { $mydir = dir ( $dir ); while ( $file = $mydir -> read ()) { if ( $file ! = '. ' && $file ! = ' ... ' ) { if ( is_dir (" $dir / $file " )) { echo ' directory name: '. $dir . Directory_separator. " $file . '
' ; Tree ( $dir / $file ""); Else { echo ' file name: '. $dir . Directory_separator. $file . '
' ; }}} $mydir -> close ();} Tree ( './phpmyadmin ');

Black-eyed poet: more PHP File system functions reference filesystem functions

http://www.bkjia.com/PHPjc/827211.html www.bkjia.com true http://www.bkjia.com/PHPjc/827211.html techarticle PHP Custom Traverse directory All file methods header (' Content-type:text/html;charset=utf-8 ');/** * Method One: Use Readir () to traverse the directory */function Listdir ($ DIR) {if (Is_dir ($ ...

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