復制代碼 代碼如下:
<?php
/**
* 遍歷目錄,找出目錄下某個後綴名的所有文件
* */
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.'<br />';
}
}
}
closedir($handle);
}
}
viewDir('E:\www\test','php');
?>