Copy code The code is as follows:
/**
* Traverse the directory and find all files with a certain suffix name in the directory
**/
function viewDir ($directory, $ext) {
if (is_dir($directory)) {
$handle = opendir($directory);
while ($file = readdir($handle)){
$subdir = $directory . '/' .$file;
if ($file != '.' && $file !=' ..' && is_dir($subdir)){
viewDir($subdir,$ext);
} else if( $file != '.' && $file != '..') {
$fileInfo = pathinfo( $subdir);
$fileExt = $fileInfo['extension'];
if ($fileExt == $ext){
echo $directory.'/'.$file.'
';
}
}
}
closedir($handle);
}
}
viewDir('E:wwwtest','php');
?>
The above has introduced the everything will flow PHP directory traversal viewDir function, including the content of everything will flow. I hope it will be helpful to friends who are interested in PHP tutorials.