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